VS CodeにPHPのスニペットを追加する

コード編集中、何度も下記の入力をするのは効率が悪い。スニペットはないか探してみた。

  <?php  ?>

html.jsonに追加

答えは簡単で、VS Code -> 管理 -> ユーザースニペット -> html.jsonを開き、スニペットを登録すれば良い。

{
	// Place your snippets for html 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"
	// }
	"php": {
		"prefix": "php",
		"body": [
			"<?php $1 ?>"
		],
		"description": "php tag"
	}
}

phpと入力すると 登録したスニペットが表示される。その状態でタブキーを押せば、コードが補完される。

PHP snipet