0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ショートカットキーで登録したコマンドをターミナルで実行するVSCodeの拡張機能

Posted at

環境

Windows 10
Version: 1.55.2

Windowsを想定して説明します。他のOSでは適宜読み替えてください。

目的

現在開いているプログラムファイルをターミナルで実行するような拡張機能はたくさんあると思いますが、自分で任意のコマンドを登録して実行させたかったので作りました。

インストール

VSCodeには面倒だったので登録していないので、GitHubからgit cloneしてください。
WindowsのVSCode拡張機能はC:\Users\xxx\.vscode\extensionsに格納されています。

cd C:\Users\xxx\.vscode\extensions
git clone https://github.com/raster0x2a/vscode-my-shortcut.git

ショートカットキーとコマンドの登録

1. VSCodeのキーバインドのファイルはC:\Users\xxx\AppData\Roaming\Code\User\keybings.jsonにあるので、そこで以下のように記述してください。

{
    "key": "[[ 登録したいショートカットキー 例: ctrl+shift+z ]]",
    "command": "my-shortcut.execInTerminal"
}

2. VSCodeの設定ファイルはC:\Users\xxx\AppData\Roaming\Code\User\settings.jsonにあるので、そこで以下のように記述してください。もし現在開いているファイルのパスを利用したい場合は、コマンドに{{filepath}}を含めて記述してください。

"my-shortcut": "[[ 実行したいコマンド 例: python {{filepath}} ]]"

3. 必要に応じてCtrl+Pで表示されるコマンドパレットでReloadと入力し、Enterで再読み込みをしてください。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?