iOSエンジニアのつぶやき

毎朝8:30に iOS 関連の技術について1つぶやいています。まれに釣りについてつぶやく可能性があります。

Visual Studio Codeでのスニペット登録

今回は、Visual Studio Code でのスニペット登録を簡単に紹介します🧑‍🔧

ちなみにバージョンは1.54.3です。

それではやっていく

まずは、Code > Preferences > User Snippets を選択します。

f:id:yum_fishing:20210321125936p:plain

次に表示されたウィンドウから、スニペットを作成したい言語を選択します。今回はJavaScriptを選択しました。

f:id:yum_fishing:20210321130411p:plain

言語を選択すると下記のようなJsonファイルが表示されますので、ここにスニペットの設定を書いていきます。

{
    // Place your snippets for javascript 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"
    // }
}

書き方はコメントに記載されている通りですが、簡単に解説すると、prefixにはトリガーとなる文字列を、bodyには展開するコードを、descriptionにはスニペットの説明をそれぞれ書いていく感じです。$1$2などは、展開後のカーソルの位置を設定するための値です。

てな感じで本日も以上になります🍺

その他の記事

yamato8010.hatenablog.com

yamato8010.hatenablog.com

yamato8010.hatenablog.com