vscode怎么創建自定義代碼片段

vscode怎么創建自定義代碼片段

這里以創建一個 javascript 代碼片段為例:

1、首先可以打開一個javascript的文件(或在當前打開文件中)按快捷鍵Ctrl+Shift+P打開命令輸入 snippet : (也可以點擊文件=>首選項=>用戶代碼片段)

vscode怎么創建自定義代碼片段

2、選擇選項后會出現一個語言列表用以選擇給哪種語言創建代碼段。這里以設置javascript的Console.WriteLine代碼段為例,其他語言方法是一樣的。

選擇javascript后會自動打開一個JSON格式的配置文件

{ 	//?Place?your?snippets?for?javascript?here.?Each?snippet?is?defined?under?a?snippet?name?and?has?a?prefix,?body?and? 	//?description.?The?prefix?is?what?is?used?to?trigger?the?snippet?and?the?body?will?be?expanded?and?inserted.?Possible?variables?are: 	//?$1,?$2?for?tab?stops,?$0?for?the?final?cursor?position,?and?${1:label},?${2:another}?for?placeholders.?Placeholders?with?the? 	//?same?ids?are?connected. 	//?Example: 	//?"Print?to?console":?{ 	//?	"prefix":?"log", 	//?	"body":?[ 	//?		"console.log('$1');", 	//?		"$2" 	//?	], 	//?	"description":?"Log?output?to?console" 	//?}, }

根據自身需要修改內容如下:

{ 	//?Place?your?snippets?for?javascript?here.?Each?snippet?is?defined?under?a?snippet?name?and?has?a?prefix,?body?and? 	//?description.?The?prefix?is?what?is?used?to?trigger?the?snippet?and?the?body?will?be?expanded?and?inserted.?Possible?variables?are: 	//?$1,?$2?for?tab?stops,?$0?for?the?final?cursor?position,?and?${1:label},?${2:another}?for?placeholders.?Placeholders?with?the? 	//?same?ids?are?connected. 	//?Example: 	"Page?Header":?{ 		"prefix":?"ducx", 		"body":?[ 			"/**", 			"?*?$1", 			"?*?", 			"?*?@author?ducx", 			"?*?@created?$CURRENT_YEAR/$CURRENT_MONTH/$CURRENT_DATE?$CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND", 			"?*/", 			"$2" 		], 		"description":?"page?header" 	} }

保存之后,打開一個 js 文件,輸入前綴 ducx?出現快捷提示窗后回車,此時已經生成了我們自定義的代碼片段結構,依次按?tab 。

/** ?*? ?*? ?*?@author?ducx ?*?@created?2018/08/31?17:08:37 ?*/

推薦教程:vscode教程

以上就是

? 版權聲明
THE END
喜歡就支持一下吧
點贊5 分享