16
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

VSCodeでVim風のカーソル移動

Posted at

【背景】

Sublime Textでvim風・Emacs風カーソル移動

この記事を参考にSublimeでVim風のカーソル移動を設定していたのですが、VSCodeでもこの設定をしたい。カーソル移動しんどい、でもVim操作をするほどVimを使ってないという問題がありました。
Key設定なんて調べればわかるものですが、上記のような記事に助けられた身としては非常に手間が省ける。

というわけで

【目的】

VSCodeでVim風のカーソル移動を設定

【方法】

  1. ⌘+K,⌘+SでKeyboard Shortcutsエディターを開き、keybindings.jsonをクリック
  2. 下記のコードを追加して保存し、キーバインドを上書きする。

[
    { "key": "ctrl+l","command": "cursorRight","when":"textInputFocus" },
    { "key": "ctrl+h","command": "cursorLeft","when": "textInputFocus" },
    { "key": "ctrl+k","command": "cursorUp","when": "textInputFocus" },
    { "key": "ctrl+j","command": "cursorDown","when": "textInputFocus" }
]

同様にEmacs風にもできます。

なお

  • "key": 割り当てるキー
  • ”command”: 実行するコマンドの名前
  • "when": キーがアクティブになるときの条件

です。

【参考】

(Sublimeの設定とキーバインドを入れたので初期設定かわかりませんが)
初期でctrl+j,ctrl+k,ctrl+hには他のショートカットが割り当てられていました。
使いたいものがあれば他の割り当てを推奨します。
また念の為、以前割り当てられていたショートカットを外す記述もしました。


    { "key": "ctrl+j","command": "-editor.action.joinLines","when": "textInputFocus" },
    { "key": "ctrl+k","command": "-deleteAllRight","when":"textInputFocus" },
    { "key": "ctrl+h","command": "-deleteLeft","when": "textInputFocus" },
  
  //ctrl+kに割り当てられてたdeleteALLRight(カーソルの右側を全消し)を使いたかったのでctrl+deleteに割り当てました
    { "key": "ctrl+delete","command": "-deleteRight","when": "textInputFocus" },
    { "key": "ctrl+delete","command": "deleteAllRight","when": "textInputFocus" }

【結論】

Sublimeのときと同じ要領でキーの割当が可能であるが上書きすることになるので、必要なショートカット華道家の確認が必要。
ショートカットキーは⌘+K,⌘+SででてくるKeyboard Shortcutsエディターで探せます。

16
11
0

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
16
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?