這篇文章將為大家詳細(xì)講解有關(guān)vscode創(chuàng)建自定義代碼片段的方法,小編覺得挺實(shí)用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
站在用戶的角度思考問題,與客戶深入溝通,找到清苑網(wǎng)站設(shè)計與清苑網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個性化、用戶體驗(yàn)好的作品,建站類型包括:成都網(wǎng)站制作、網(wǎng)站設(shè)計、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名注冊、網(wǎng)頁空間、企業(yè)郵箱。業(yè)務(wù)覆蓋清苑地區(qū)。
這里以創(chuàng)建一個 javascript 代碼片段為例:
1、首先可以打開一個javascript的文件(或在當(dāng)前打開文件中)按快捷鍵Ctrl+Shift+P打開命令輸入 snippet : (也可以點(diǎn)擊文件=>首選項(xiàng)=>用戶代碼片段)
2、選擇選項(xiàng)后會出現(xiàn)一個語言列表用以選擇給哪種語言創(chuàng)建代碼段。這里以設(shè)置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" // }, }
根據(jù)自身需要修改內(nèi)容如下:
{ // 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 出現(xiàn)快捷提示窗后回車,此時已經(jīng)生成了我們自定義的代碼片段結(jié)構(gòu),依次按 tab 。
/** * * * @author ducx * @created 2018/08/31 17:08:37 */
關(guān)于“vscode創(chuàng)建自定義代碼片段的方法”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。