【工具配置】vscode自定义用户代码片段(写代码超爽感觉)

背景

  • 我听说很多人觉得webstorm写代码爽因为打个log就会出console.log出来,其实vscode也能设置的,而且掌握这个技巧写代码真的是太爽了。以前觉得react类组件写的真累,都是重复的代码,里面就有点不一样而已,有这个技巧就像写html模板一样按个感叹号就出来一堆代码超爽。

方法

  • vscode左下角有个齿轮图标,点击齿轮,然后选择user snippers
  • 会看到类似搜索框的东西,会让你选择是全局通用还是就这个项目用,根据需求来,全局就golobal。
  • 然后会让你起个文件名,随便起个名字就行了,然后它注释例子都给你写好了。
{
	// 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": "log",
	// 	"body": [
	// 		"console.log('$1');",
	// 		"$2"
	// 	],
	// 	"description": "Log output to console"
	// }
		"Print to console": {
		"scope": "javascript,typescript",
		"prefix": "lg",
		"body": [
			"console.log('$1');",
			"$2"
		],
		"description": "Log output to console"
	}
}
  • 仿照例子复制一下,把prefix改成自己喜欢的,比如按lg就能打出console.log(‘xxx’)。
  • $1和$2是占位符,这个更爽,就是按lg后光标直接跳到$1的位置,再按下tab,光标跳$2的位置。
  • 保存即可,然后新建个js文件试试是不是感觉超爽。

你可能感兴趣的:(工具配置)