1.在VSCode设置 > 配置用户代码片段菜单添加
2.在输入框中选择新建代码片段
文章来源:https://www.toymoban.com/news/detail-445211.html
3.输入代码片段名称.例如:copyright
4. 生成第3步名称的代码片段文件,默认位置:C:\Users\你的电脑名称\AppData\Roaming\Code\User\snippets
5. 代码片段模板的解释如下: 重点关注scope+prefix+body参数的配置,
5.1 scope是代码片段适用的语言, 不配置则默认适用所有语言
5.2 prefix 前缀,也就是快捷指令,在编辑器中输入快捷指令即可快速加载出该代码片段
5.3 body 也就是代码片段的内容, 支持环境变量及可选入参
6. 根据模板编写代码片段后保存,body中支持换行符 制表符等特殊字符
7.在编辑区域即可通过prefix 中配置的快捷指令来快速插入body中的内容
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文章来源地址https://www.toymoban.com/news/detail-445211.html
到了这里,关于VSCode代码片段配置的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!