Skip to main content

設定. 操作性. 左側のツリーをキーボード操作したい

やりたいこと

  • キーボード操作(hjklか矢印)で、ファイルを選択しながら中身をブラウズしたい

デフォルトで出来ること

こんな感じの動作となってる。

操作動作
1. Cmd + Shift + EエクスプローラにフォーカスをToggle
# Toggle でなくて良いのだけど
2. , フォーカス移動
3. , フォルダの開閉
4. Enter (Mac: Cmd + ↓)ファイルを開く (編集)
5. Space選択 + ファイルを開く(プレビュー) + 編集画面にフォーカス
6. F2 (Mac: Enter)ファイル名を編集
7. 文字列入力ファイルのインクリメンタルサーチ

設定で出来ること

やりたいこと理由設定項目
5編集画面にフォーカス させない左側にフォーカスを残したままにしいexplorer.autoReveal をオフ
7ファイルのインクリメンタルサーチ させないhjkl をキー割り当てしたいworkbench.list.automaticKeyboardNavigation をオフ
エクスプローラにフォーカスを戻すときに、開いていたファイルを選択したいshowActiveFileInExplorer をキー割り当て

拡張機能とキー割当で出来ること

  • 25 を 1 操作で出来るようにする
    • → 拡張機能の macros で command を定義
  • vi 風に h j k l で操作出来るようにする
    • automaticKeyboardNavigation は便利だから、結局 矢印のみ設定した

最終的に追加した内容

settings.json

json
    "explorer.autoReveal": false,
"workbench.list.automaticKeyboardNavigation": false,

"macros": {
"list.focusUpAndPreview": [
"list.focusUp",
"filesExplorer.openFilePreserveFocus",
// "list.selectAndPreserveFocus",
],
"list.focusDownAndPreview": [
"list.focusDown",
"filesExplorer.openFilePreserveFocus",
// "list.selectAndPreserveFocus",
],
},

keybindings.json

json
    { "key": "cmd+shift+e" , "command": "workbench.files.action.showActiveFileInExplorer", "when": "inputFocus" },
{ "key": "left" , "command": "list.collapse" , "when": "explorerViewletFocus && explorerViewletVisible && !inputFocus" },
{ "key": "down" , "command": "macros.list.focusDownAndPreview" , "when": "explorerViewletFocus && explorerViewletVisible && !inputFocus" },
{ "key": "up" , "command": "macros.list.focusUpAndPreview" , "when": "explorerViewletFocus && explorerViewletVisible && !inputFocus" },
{ "key": "right" , "command": "list.expand" , "when": "explorerViewletFocus && explorerViewletVisible && !inputFocus" },

課題

  • カーソル移動と同時にファイルも選択されてほしい
    • list.selectAndPreserveFocus を考えていたが、
      • フォルダ選択時に開く/閉じるがトグルされてしまう
    • keybindings の when に !explorerResourceIsFolder を設定することも考えたが、、
      • ファイルかフォルダがわかるのはカーソル移動後なので、不採用
    • macros で 分岐が出来れば良いが