1.在VSCode設置 > 配置用戶代碼片段菜單添加
?2.在輸入框中選擇新建代碼片段
?文章來源:http://www.zghlxwxcb.cn/news/detail-445211.html
3.輸入代碼片段名稱.例如:copyright
4. 生成第3步名稱的代碼片段文件,默認位置:C:\Users\你的電腦名稱\AppData\Roaming\Code\User\snippets
5. 代碼片段模板的解釋如下: 重點關注scope+prefix+body參數(shù)的配置,
? ? ? ? 5.1 scope是代碼片段適用的語言, 不配置則默認適用所有語言
? ? ? ? 5.2?prefix 前綴,也就是快捷指令,在編輯器中輸入快捷指令即可快速加載出該代碼片段
? ? ? ? 5.3?body 也就是代碼片段的內(nèi)容, 支持環(huán)境變量及可選入?yún)?/p>
?6. 根據(jù)模板編寫代碼片段后保存,body中支持換行符 制表符等特殊字符
?
7.在編輯區(qū)域即可通過prefix 中配置的快捷指令來快速插入body中的內(nèi)容
?8. body中關于變量的用法
?
TM_SELECTED_TEXT The currently selected text or the empty string
TM_CURRENT_LINE The contents of the current line
TM_CURRENT_WORD The contents of the word under cursor or the empty string
TM_LINE_INDEX The zero-index based line number
TM_LINE_NUMBER The one-index based line number
TM_FILENAME The filename of the current document
TM_FILENAME_BASE The filename of the current document without its extensions
TM_DIRECTORY The directory of the current document
TM_FILEPATH The full file path of the current document
RELATIVE_FILEPATH The relative (to the opened workspace or folder) file path of the current document
CLIPBOARD The contents of your clipboard
WORKSPACE_NAME The name of the opened workspace or folder
WORKSPACE_FOLDER The path of the opened workspace or folder
CURSOR_INDEX The zero-index based cursor number
CURSOR_NUMBER The one-index based cursor number
For inserting the current date and time:
CURRENT_YEAR The current year
CURRENT_YEAR_SHORT The current year's last two digits
CURRENT_MONTH The month as two digits (example '02')
CURRENT_MONTH_NAME The full name of the month (example 'July')
CURRENT_MONTH_NAME_SHORT The short name of the month (example 'Jul')
CURRENT_DATE The day of the month as two digits (example '08')
CURRENT_DAY_NAME The name of day (example 'Monday')
CURRENT_DAY_NAME_SHORT The short name of the day (example 'Mon')
CURRENT_HOUR The current hour in 24-hour clock format
CURRENT_MINUTE The current minute as two digits
CURRENT_SECOND The current second as two digits
CURRENT_SECONDS_UNIX The number of seconds since the Unix epoch
For inserting random values:
RANDOM 6 random Base-10 digits
RANDOM_HEX 6 random Base-16 digits
UUID A Version 4 UUID
For inserting line or block comments, honoring the current language:
BLOCK_COMMENT_START Example output: in PHP /* or in HTML <!--
BLOCK_COMMENT_END Example output: in PHP */ or in HTML -->
LINE_COMMENT Example output: in PHP //
?例如:
?
?
?
?9. 更多用法請參考:?Snippets in Visual Studio Code文章來源地址http://www.zghlxwxcb.cn/news/detail-445211.html
到了這里,關于VSCode代碼片段配置的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!