Visual Studio Code(VS Code) 自定义代码块

先点击屏幕左下角的齿轮图标按钮,然后点击User Snippets

选择新建一个代码块文件,当然也可以使用默认的。

输入文件名称,输入完成后按下回车键就可以新建了,以后还需要修改代码块就直接搜索名称即可,需要重新新建。

这个样子就是新建成功了

这一段英文大概得意思是,将全局代码片段放在这里。每个代码段在代码段名称下定义,并具有作用域、前缀、主体和描述。在scope字段中添加以逗号分隔的代码片段适用的语言id。如果范围为空或省略,则该代码段将应用于所有语言。前缀是什么用于触发代码片段,然后展开并插入代码体。可能的变量有: $1, $2表示制表符,$0表示光标的最终位置,${1:label}, ${2:another}表示占位符。连接具有相同id的占位符。

这里我补充一下几个字段的意思

scope : 此代码段使用的语言名称列表,例如 "typescript,javascript"。

 prefix : 在 Intellisense 中选择代码片段时要使用的前缀 

body :片段内容。

 description : 代码片段描述。

下满写入自己的代码块这里给大家分析一个 代码块底代码生成工具 

{
	// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and 
	// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope 
	// is left empty or omitted, the snippet gets applied to all languages. 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": {
		"scope": "javascript,typescript",
		"prefix": "clog",
		"body": [
			"console.log('$1');",
			"$2"
		],
		"description": "Log output to console"
	},
	"vue code": {
		"prefix": "vue template",
		"body": [
			"<template>",
			"\t<div>",
			" ",
			"\t</div>",
			"</template>",
			"<script>",
			"export default {",
			"\tname:'',",
			"\tcomponents: {",
			" ",
			"\t},",
			"\tdata() {",
			"\t\treturn {",
			" ",
			"\t\t}",
			"\t},",
			"\tcreated() {",
			"",
			"\t},",
			"\tmethods: {",
			" ",
			"\t},",
			"}",
			"</script>",
			"<style lang=\"scss\" scoped>",
			" ",
			"</style>"
		],
		"description": "vue2 basic module"
	}
}

注册完成后就可以去试试了

这样一个全局代码块就弄好啦

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要更新 Visual Studio Code 中的代码,你可以按照以下步骤进行操作: 1. 首先,确保你已经打开了需要更新的代码文件。 2. 接下来,你可以使用 Visual Studio Code 提供的编辑功能来修改代码。你可以添加、删除或修改代码行,以满足你的需求。 3. 如果你想使用预定义的代码片段来快速插入一些常用代码块,你可以使用 IntelliSense 功能来查找和插入代码片段。当你输入代码时,IntelliSense 会提供相关的代码片段建议,你可以选择其中一个并按下 Enter 键来插入它。 4. 如果你想自定义代码片段或修改现有的代码片段,你可以打开 Visual Studio Code 的用户设置,并搜索 "代码片段" 相关的设置。在设置中,你可以找到有关代码片段的配置选项,并根据提示进行修改。 5. 最后,当你完成对代码的更新后,你可以保存文件并测试修改后的代码是否按预期工作。 总结起来,要更新 Visual Studio Code 中的代码,你可以通过编辑代码文件、使用代码片段以及自定义代码片段来实现。记得保存文件并测试修改后的代码。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [[VS Code]跟我一起在Visual Studio Code 添加自定义snippet(代码段),附详细配置](https://blog.csdn.net/maokelong95/article/details/54379046)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值