設定. 操作性. 左側のツリーをキーボード操作したい
やりたいこと
- キーボード操作(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 をキー割り当て |
拡張機能とキー割当で出来ること
2
→5
を 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 で 分岐が出来れば良いが