LoginSignup
4
2

More than 3 years have passed since last update.

markdownのスニペット登録

Last updated at Posted at 2020-10-07

はじめに

VSCodeを使ってマークダウン形式でミーティングの議事録をとる機会が増えたので、スニペット機能を使ってテンプレートを登録したい。
ということで登録していったが、1箇所詰まったので、備忘録として残す。

サンプルコード

スニペットの登録

VSCodeの設定から、スニペットの設定>markdown.json、を探す。
以下のようなスニペットのサンプルが記載されたファイルが見つかるはず。

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

上記ファイルを下記のように修正する。

snippets/markdown.json
{
  "Minutes template": {
    "prefix": "minutes",
    "body": [
      "# $1 Daily MTG",
      "## 議題",
      "- $2",
      "- $3",
      "- $4",
      "",
      "## $2",
      "- ",
      "",
      "## $3",
      "- ",
      "",
      "## $4",
      "- ",
      "",
    ],
    "description": "Daily MTG minute"
  },

Markdown形式のファイルでスニペットを使えるようにする(必要であれば)

スニペットを登録すればすぐに使える場合もあるが、自分の環境では使えなかった。
解決策として、VSCodeのsettings.jsonファイルにmarkdownについて追記したら使えるようになった。

settings.json
{
    "workbench.startupEditor": "newUntitledFile",
    "editor.tabSize": 2,
    "editor.suggestSelection": "first",
    "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
    "java.home": "",
    "window.zoomLevel": 0,
    // 以下を追加
    "[markdown]": {
        "editor.wordWrap": "on",
        "editor.quickSuggestions": true,
        "editor.snippetSuggestions": "top",
    }
}

動作

  1. minutesと入力して、登録したスニペットを呼び出す
  2. $1に設定した項目に入力後、tabキーを押して次の$2を入力…(以下略)

demo01.gif

参考

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2