
vscode のショートカットキー設定方法(JSON) とか
目次
公式ドキュメント
https://code.visualstudio.com/docs/getstarted/keybindings
基本的な設定方法
ctrl+shift+pでコマンドパレットを表示してshortcutと入力しPreferences: Open Default Keyboard Shortcuts (JSON)とPreferences: Open Keyboard Shortcuts (JSON)を開く。Preferences: Open Default Keyboard Shortcuts (JSON)の方からctrl+fで、それらしいコマンド名を検索するか JSON なのでctrl+shift+oを使ってキーをシンボルとして探す。設定したいショートカットキーを
Preferences: Open Keyboard Shortcuts (JSON)に書く。"key"設定したいキー"command"割り当てる動作"when"条件(必要なければ書かなくていい。条件演算子==,!=,||,&&を使って if 文のように書ける)"args"文字を挿入したりするのに使う。Go 言語ならエラーハンドリングif err != nil {...}を書くのに良さそう。 詳しくはドキュメントのCommand argumentsを参照
[
{
"key": "ctrl+n",
"command": "cursorDown",
"when": "editorTextFocus"
}
]
Preferences: Open Default Keyboard Shortcuts (JSON) の一番下にあるコメントになってる command はデフォルトで未割り当てのやつ
削除
間違って押してイラッとしたらそのキーは削除しておくとよい。
(例えば、エディターを閉じたい場合は Alt + F4 で閉じればいいので ctrl+q とか)
デフォルトで設定してある動作の削除。"command" の値の最初に - を付ける。
[
{
"key": "ctrl+q",
"command": "-workbench.action.quit"
}
]
"command" の値を空にしてすべての動作を削除。
[
{
"key": "ctrl+q",
"command": ""
}
]
便利なショートカットキー
f12 定義ジャンプ(めっちゃ便利) ctrl + e ファイルを検索して開く ctrl + shift + e エクスプローラーにフォーカス(サイドバーを開いてなければ開く) ctrl + f 現在開いているファイル内を検索 ctrl + shift + f 開いているディレクトリ以下のすべてのファイルを検索 ctrl + h 現在開いているファイルの文字を置換 ctrl + shift + h 開いているディレクトリ以下のすべてのファイルの文字を置換 ctrl + shift + o シンボルを検索(関数名とかクラス名とか検索して移動する) ctrl + shift + v マークダウンプレビュー atl + r ctrl+f などの検索で正規表現を使う atl + c ctrl+f などの検索で大文字小文字を区別する
設定サンプル
自分が設定してるキーバインド。(エディタ遍歴がでるので emacs + sublime text + tmux 風)
[
// Unbind
{ "key": "ctrl+q", "command": "-workbench.action.quit" },
{ "key": "ctrl+o", "command": "-workbench.action.files.openFile" },
{ "key": "ctrl+k f", "command": "-workbench.action.closeFolder", },
{ "key": "ctrl+k u", "command": "-workbench.action.closeUnmodifiedEditors" },
// Moving the cursor ------------------
{
"key": "ctrl+b",
"command": "cursorLeft",
"when": "editorTextFocus"
},
{
"key": "ctrl+n",
"command": "cursorDown",
"when": "editorTextFocus"
},
{
"key": "ctrl+f",
"command": "cursorRight",
"when": "editorTextFocus"
},
{
"key": "ctrl+p",
"command": "cursorUp",
"when": "editorTextFocus"
},
{ // Move to end of word
"key": "ctrl+shift+b",
"command": "cursorWordStartLeft",
"when": "editorTextFocus"
},
{ // Move to begin of word
"key": "ctrl+shift+f",
"command": "cursorWordEndRight",
"when": "editorTextFocus"
},
// Focus behavior ----------------------
{
"key": "ctrl+o b",
"command": "workbench.action.toggleSidebarVisibility",
"when": "editorTextFocus"
},
{
"key": "ctrl+o f",
"command": "workbench.action.focusSideBar",
"when": "editorTextFocus"
},
{
"key": "ctrl+o f",
"command": "workbench.action.focusActiveEditorGroup",
"when": "!editorTextFocus"
},
{
"key": "ctrl+o t",
"command": "workbench.action.terminal.toggleTerminal",
},
{
"key": "ctrl+o o",
"command": "workbench.action.output.toggleOutput",
},
{
"key": "ctrl+o p",
"command": "workbench.action.togglePanel",
},
// Editor layout -------------------
{
"key": "ctrl+o shift+'",
"command": "workbench.action.splitEditorDown"
},
{
"key": "ctrl+o shift+5",
"command": "workbench.action.splitEditor"
},
{ // Focus on the next EDITOR that is split
"key": "ctrl+o l",
"command": "workbench.action.focusNextGroup"
},
{ // Focus on the previous EDITOR that is split
"key": "ctrl+o h",
"command": "workbench.action.focusPreviousGroup"
},
{
"key": "ctrl+o j",
"command": "workbench.action.focusBelowGroup"
},
{
"key": "ctrl+o k",
"command": "workbench.action.focusAboveGroup"
},
// Terminal -----------------------
{
"key": "ctrl+p",
"command": "cursorUp",
"when": "terminalFocus"
},
{
"key": "ctrl+n",
"command": "cursorDown",
"when": "terminalFocus"
},
{
"key": "ctrl+f",
"command": "cursorRight",
"when": "terminalFocus"
},
{
"key": "ctrl+b",
"command": "cursorLeft",
"when": "terminalFocus"
},
{
"key": "ctrl+a",
"command": "cursorHome",
"when": "terminalFocus"
},
{
"key": "ctrl+e",
"command": "cursorEnd",
"when": "terminalFocus"
},
{
"key": "ctrl+h",
"command": "deleteLeft",
"when": "terminalFocus"
},
{
"key": "ctrl+d",
"command": "deleteRight",
"when": "terminalFocus"
},
{
"key": "ctrl+k",
"command": "deleteAllRight",
"when": "terminalFocus"
},
// Search -------------------------
{
"key": "ctrl+q",
"command": "actions.find"
},
{
"key": "ctrl+shift+q",
"command": "workbench.view.search"
},
// Find Replace -------------------
{
"key": "ctrl+r",
"command": "editor.action.startFindReplaceAction"
},
{
"key": "ctrl+shift+r",
"command": "workbench.action.replaceInFiles"
},
// New file -----------------------
{
"key": "ctrl+shift+n",
"command": "workbench.action.files.newUntitledFile"
},
// Deletion -----------------------
{
"key": "ctrl+h",
"command": "deleteLeft",
"when": "editorTextFocus"
},
{
"key": "ctrl+shift+h",
"command": "deleteWordLeft",
"when": "editorTextFocus"
},
// Selection ----------------------
{
"key": "ctrl+l",
"command": "expandLineSelection",
"when": "editorTextFocus"
},
{
"key": "ctrl+9",
"command": "cursorRightSelect",
"when": "textInputFocus"
},
{
"key": "ctrl+8",
"command": "cursorLeftSelect",
"when": "textInputFocus"
},
{
"key": "ctrl+shift+9",
"command": "cursorWordEndRightSelect",
"when": "textInputFocus"
},
{
"key": "ctrl+shift+8",
"command": "cursorWordLeftSelect",
"when": "textInputFocus"
},
// Duplication -----------------------
{
"key": "ctrl+shift+d",
"command": "editor.action.copyLinesDownAction",
"when": "editorTextFocus"
},
// Move line -------------------------
{
"key": "ctrl+down",
"command": "editor.action.moveLinesDownAction",
"when": "editorTextFocus"
},
{
"key": "ctrl+up",
"command": "editor.action.moveLinesUpAction",
"when": "editorTextFocus"
},
// Suggestion -------------------------
{
"key": "ctrl+n",
"command": "selectNextSuggestion",
"when": "editorTextFocus && suggestWidgetVisible"
},
{
"key": "ctrl+p",
"command": "selectPrevSuggestion",
"when": "editorTextFocus && suggestWidgetVisible"
},
// Multi cursor -----------------------
{
"key": "ctrl+shift+up",
"command": "editor.action.insertCursorAbove",
"when": "editorTextFocus"
},
{
"key": "ctrl+shift+down",
"command": "editor.action.insertCursorBelow",
"when": "editorTextFocus"
},
// Join lines -------------------------
{
"key": "ctrl+j",
"command": "editor.action.joinLines"
},
// Change to uppercase/lowercase ------
{
"key": "ctrl+o ctrl+u",
"command": "editor.action.transformToUppercase",
"when": "editorTextFocus"
},
{
"key": "ctrl+o ctrl+l",
"command": "editor.action.transformToLowercase",
"when": "editorTextFocus"
}
]