VSCode建立自定義代碼段

上一篇:PyCharm建立自定義代碼段(JetBrains系列通用)javascript

設置方法

很簡單,快速過一下,F1,而後輸入snippetshtml

而後選擇對應語言前端

 

Python案例

內容和使用:html5

{
	// prefix:這個參數是使用代碼段的快捷入口,好比這裏的ifmain在使用時輸入ifmain會有智能感知
	// body:這個是代碼段的主體.須要設置的代碼放在這裏,字符串間換行的話使用\r\n換行符隔開.注意若是值裏包含特殊字符須要進行轉義,多行語句的以,隔開
	// $1:這個爲光標的所在位置.
	// $2:使用這個參數後會光標的下一位置將會另起一行,按tab鍵可進行快速切換,還能夠有$3,$4,$5.....
	// description:代碼段描述,在使用智能感知時的描述
	"Print to console": {
		"prefix": "ifmain",
		"body": [
			"",
			"def main():",
			"    ${1:pass}",
			"",
			"",
			"if __name__ == \"__main__\":",
			"    main()",
			""
		],
		"description": "if main"
	}
}

 而後輸入你設置的縮略就能夠了,GIF演示下:java

{
    "Print to console": {
        "prefix": "ifmain",
        "body": [
            "",
            "def main():",
            "    ${1:pass}",
            "",
            "",
            "if __name__ == \"__main__\":",
            "    main()",
            ""
        ],
        "description": "if main"
    },
    "asyncio method": {
        "prefix": "asyncmain",
        "body": [
            "",
            "async def main():",
            "    ${1:pass}",
            "",
            "",
            "if __name__ == \"__main__\":",
            "    import time",
            "    start_time = time.time()",
            "",
            "    asyncio.run(main())",
            "",
            "    print(time.time() - start_time)",
            ""
        ],
        "description": "async main"
    }
}

前端案例

{
	"doc for html5": {
		"prefix": "html5",
		"body": [
			"<!DOCTYPE html>",
			"<html>",
			"<head>",
			"    <meta charset=\"UTF-8\">",
    		"    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\">",
	"    <title>${1:標題}</title>",
			"</head>",
			"<body>",
			"    ${2}",
			"</body>",
			"</html>"
		],
		"description": "快速生成HTML5"
	}
}
相關文章
相關標籤/搜索