vscode配置自定义代码片段:比如:让vscode具有和IDEA一样的代码段生成快捷键(sout或psvm)的配置方法为例说明

配置vscode的java.json(依此为例子)

alt+shift+p配置

在这里插入图片描述
输入preferences:configure user Snippets

再输入java,点击确认,编辑java.json
在这里插入图片描述
在这里插入图片描述

或则直接按路径找到java.json

根据文件中的注释内容给出的json说明,可以自行配置

配置样例:将里面的内容用如下代码覆盖(比如:添加sout,psvm的补全效果)

{
    
    
	// Place your snippets for java 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"
	// }
	"main 代码段": {
    
    
		"prefix": "psvm",
		"body": [
			"public static void main(String[] args){",
			"\t$1",
			"}"
		],
		"description": "main代码段"
	},
	"print": {
    
    
		"prefix": "sout",
		"body": [
			"System.out.println(\"$1\");"
			// "${1:}",
			// ")"
		],
		"description": "System.out.println"
	}
}

具体怎加的代码为:(可以不必深究)

"main 代码段": {
    
    
		"prefix": "psvm",
		"body": [
			"public static void main(String[] args){",
			"\t$1",
			"}"
		],
		"description": "main代码段"
	},
	"print": {
    
    
		"prefix": "sout",
		"body": [
			"System.out.println(\"$1\");"
			// "${1:}",
			// ")"
		],
		"description": "System.out.println"
	}

效果(注意不要太着急enter/tab,不然vscode还没反应过来)

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/xuchaoxin1375/article/details/114596694