みねっちょのマイコン関係ブログ

組込開発系フリーソフトやハードの情報発信ブログ

VSCode のターミナル内 bash のキーバインドを Emacs に戻す

サイト内 Google 検索:


最終更新: 2021-05-06
VSCode (Visual Studio Code) エディタのターミナル機能でシェルを起動すると、bashEmacs モードのキーバインドが上書きされて VSCodeキーバインドになっています。これを VSCode の機能で再度上書きし、Emacs モードに戻す方法を紹介します。

目次:

ファイルを開く:

VSCodeCtrl+Shift+P を押してコマンドパレットを開き、preferenceと入力して検索後、基本設定: キーボードショートカットを開く (JSON) Preference: Open Keyboard Shortcuts (JSON) を押します。末尾に (JSON) が付いて居る事に注意してください。開かれるのは、次のファイルです。VSCode 以外のエディタで編集しても問題有りません。

Windows の場合:

C:\Users\%USERNAME%\AppData\Roaming\Code\User\keybindings.json

Linux の場合:

~/.config/Code/User/keybindings.json

【広告】


コードを貼り付ける:

次のコードの [] で囲まれた内部を貼り付けます。Ctrl 系の1文字シーケンスしか記述していませんので、Meta 系のシーケンスや2文字シーケンスが必要な方は、追加してください。
尚、記述は when 節を使用する事により、このキーバインドはターミナル内でのみ有効となっています。また、ファイルをセーブした時点からキーバインドは有効となります。上部タブの「ファイル」⇒「保存」でファイルをセーブします。
尚、undo は Ctrl+_ に割り振られています。

[
    { "key": "ctrl+b",              "command": "cursorLeft",                                "when": "terminalFocus" },
    { "key": "ctrl+f",              "command": "cursorRight",                               "when": "terminalFocus" },
    { "key": "ctrl+p",              "command": "cursorUp",                                  "when": "terminalFocus" },
    { "key": "ctrl+n",              "command": "cursorDown",                                "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" },
    { "key": "ctrl+u",              "command": "deleteAllLeft",                             "when": "terminalFocus" },
    { "key": "ctrl+w",              "command": "deleteWordPartLeft",                        "when": "termianlFocus" },
    { "key": "ctrl+y",              "command": "paste",                                     "when": "terminalFocus" },
    { "key": "crtl+t",              "command": "deleteLeft; cursorRight; paste",            "when": "terminalFocus" },
    { "key": "ctrl+m",              "command": "editor.action.insertLineAfter",             "when": "terminalFocus" },
    { "key": "ctrl+j",              "command": "editor.action.insertLineAfter",             "when": "terminalFocus" },
    { "key": "ctrl+o",              "command": "editor.action.insertLineAfter; cursorDown", "when": "termianlFocus" },
    { "key": "ctrl+i",              "command": "workbench.action.terminal.sendSequence", "args": { "text": "\u0009" } , "when": "termianlFocus" },
    { "key": "ctrl+l",              "command": "workbench.action.terminal.clear",           "when": "terminalFocus" },
    { "key": "ctrl+r",              "command": "workbench.action.terminal.sendSequence", "args": { "text": "\u0012" } , "when": "termianlFocus" },
    { "key": "ctrl+g",              "command": "workbench.action.terminal.clearSelection",  "when": "termianlFocus" },
    { "key": "ctrl+space",          "command": "setSelection",                              "when": "terminalFocus" },
    { "key": "ctrl+oem_3",          "command": "setSelection",                              "when": "terminalFocus" }, // Ctrl-@
    { "key": "ctrl+shift+oem_102",  "command": "workbench.action.terminal.sendSequence", "args": { "text": "\u001f" } , "when": "termianlFocus" } // Ctrl-_
]

【広告】


キーバインドの意味:

設定した各キーバインドの意味は、次の通りとなります。

キーバインド 機能
Ctrl-b 1文字戻る (← と同等)
Ctrl-f 1文字進む (→ と同等)
Ctrl-p 1つ前のコマンド履歴を表示する (↑ と同等)
Crtl-n 1つ後のコマンド履歴を表示する (↓ と同等)
Ctrl-a 行頭へ移動する (HOME |◀ と同等)
Ctrl-e 行末へ移動する (END ▶| と同等)
Ctrl-h 直前の文字を消す (BS と同等)
Crtl-d カーソル位置で1文字消去する (DEL と同等)
削除すべき文字が無い場合は EOF の意味となります。
.bashrcset -o ignoreeof を設定しておかないと
ログアウトします。
Ctrl-k 現在のカーソル位置から行末までを消去
Ctrl-u 行頭から現在のカーソル位置の直前までを消去
Ctrl-w ワードの先頭から現在のカーソル位置の直前までを消去
Ctrl-y 消去した文字列を挿入
Ctrl-t 現在のカーソル位置と直前の文字を入れ替え
Ctrl-m 復帰 (ENTER と同等)
Ctrl-j 改行 (ENTER と同等)
Ctrl-o 復帰 (ENTER) だが、実行後に1つ後の履歴を表示
Ctrl-i コマンドのコンプリーション (TABと同等)
Ctrl-l クリア スクリーン (clear コマンドと同等)
Ctrl-r 履歴のインクリメンタル「逆」サーチ
Ctrl-g 入力済のキーシーケンスの中断
Ctrl-SPACE
Ctrk-@
現在のカーソル位置をマーク
Ctrl-_ undo

【WSL 関係の目次へ戻る】