LoginSignup
18
14

More than 1 year has passed since last update.

Visual Studio Codeでキーボードショートカットに外部コマンドを割り当てる

Last updated at Posted at 2018-02-05

やりたいこと

VisualStudioCodeでCtrl+Qを押したとき、開いているフォルダにあるhoge.batを実行してほしい。

手順

以下の手順で設定できます。バージョン1.57.1で確認しています。

1. タスクにhoge.batを登録する

  1. Ctrl+Shift+Pでコマンドパレットを開き、「Tasks: Configure Task」を実行する
  2. 「テンプレートからtasks.jsonを生成」を選ぶ
  3. 「Others」を選ぶ
  4. tasks.jsonが開かれるので、以下のように編集する
tasks.json
{
  // See https://go.microsoft.com/fwlink/?LinkId=733558
  // for the documentation about the tasks.json format
  "version": "2.0.0",
  "tasks": [
    {
      "label": "runHoge", // タスクの名前
      "type": "shell",
      "command": "hoge.bat" // 実行したいコマンド
    }
  ]
}

実行したいコマンドを変更すれば好きな外部コマンドを登録できます。

2. 登録したタスクにキーボードショートカットを割り当てる

  1. Ctrl+Shift+Pでコマンドパレットを開き、「Preferences: Open Keyboard Shortcuts(JSON)」を実行する
  2. keybindings.jsonが開かれるので、以下のように編集する
keybindings.json
// 既定値を上書きするには、このファイル内にキー バインドを挿入します
[
  {
    "key": "Ctrl+Q",
    "command": "workbench.action.tasks.runTask",
    "args": "runHoge", // tasks.jsonで設定したタスクの名前
  }
]

"key"に割り当てたいキー、"args"に実行するタスクの名前を指定します。

18
14
3

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
18
14