LoginSignup
6
4

More than 5 years have passed since last update.

VS CodeのExplorerでVim風に移動する

Posted at

VS Codeは多機能で大変便利なのですが、Vimにある程度なれると移動に↑↓←→キーを使うのが億劫になります。

特にFile Explorerでディレクトリ構造を見ながらファイルを開きたいというときにキーボードのホームポジションを崩して↑↓←→キーで移動するのが辛くてどうにかできないか調べたのでその備忘録です。

VSCode version: 1.31.1

とりあえず結論

  • VSCodeVim Extension を入れる
  • setting.jsonで"workbench.list.keyboardNavigation": "simple"にする

実は既にVSCodeVim Extensionでサポートされている

Googleで適当に「vscode explorer vim binding」で調べた結果、以下のIssueを見つけました。

Using j,k,l,i to navigate inside explorer list #754
https://github.com/VSCodeVim/Vim/issues/754

それによると2017年の6月の時点でVSCodeVim Extensionを入れていればExplorerでもVim風な移動ができるみたいです!

VSCodeVim Extensionは入れていたので早速試してみました!

Screen Shot 2019-03-03 at 12.33.48.png

どうやらVSCodeの別の機能にキーを奪われてVim風な移動ができなくなっているみたいです。。。

Listのハイライト表示機能をOffにする

とりあえずまたGoogleで適当に「vscode explorer search」で調べて適当にIssueを漁っていたら以下のコメントを見つけました。

List Keyboard Navigationというそれっぽい機能があるようなのでさっそく確認してみたところ、

Screen Shot 2019-03-03 at 12.41.51.png

  • highlight(私の環境だとデフォルト)
  • filter
  • simple

があり、simpleに変えてみたところ、無事にjkキーでリストの移動ができました🎉

Keybinding

2019/3月現在、VSCodeVim Extensionを入れるとリストで以下の操作が有効になるみたいです。

キー コマンド
h list.collapse
j list.focusDown
k list.focusUp
l list.select
o list.toggleExpand
/ list.toggleKeyboardNavigation
ctrl+d list.focusPageDown
ctrl+u list.focusPageUp
g g list.focusFirst
G list.focusLast

ただ、いくつかの挙動が怪しくて/とか動作しているのかいまいちわかりませんでした。

まとめ

VSCodeのExplorerでVim風に移動するやり方を紹介しました。
個人的にhjklで操作するだけでVSCodeがさらに快適になり、よかったです。
また、keybinding.jsonにキーバインディングの設定を書くときに"when": "listFocus && !inputFocus"を付け加えることでオリジナルのリスト操作中のキーバインディングを自作することができそうなので色々いじってみたいと思います!

6
4
1

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
6
4