DEV Community

Apestein
Apestein

Posted on • Edited on

Intuitive Vim Keybinding For VScode😏

Is vim hard to pick up? Well, not anymore with my intuitive keybindings for VScode vim extension.

{
  "vim.normalModeKeyBindings": [
    {
      "before": ["k"],
      "commands": ["cursorDown"]
    },
    {
      "before": ["i"],
      "commands": ["cursorUp"]
    },
    {
      "before": ["j"],
      "commands": ["cursorLeft"]
    },
    {
      "before": ["l"],
      "commands": ["cursorRight"]
    },
    {
      "before": ["h"],
      "after": ["<insert>"]
    },
  ],
  "vim.visualModeKeyBindingsNonRecursive": [
    {
      "before": ["h"],
      "after": ["i"]
    },
    {
      "before": ["i"],
      "after": ["k"]
    },
    {
      "before": ["k"],
      "after": ["j"]
    },
    {
      "before": ["j"],
      "after": ["h"]
    },
    {
      "before": ["h"],
      "after": ["i"]
    }
  ],
}
Enter fullscreen mode Exit fullscreen mode

Now "i" is up, "k" is down, "j" is left, "l" is right and "h" is insert. If you have played any pc games, this movement will feel right at home.

Now some more tips to increase your vim productivity

  1. Rebind capslock to escape. For linux you can use "tweaks" from the Ubuntu Store and for windows you can use "powertoys".

Image description
After settings capslock as additional escape in "Tweaks" you must then change keybinding in vscode like below, if you do it in the wrong order it will not work.

[
{
    "key": "capslock",
    "command": "extension.vim_escape",
    "when": "editorTextFocus && vim.active && !inDebugRepl"
  },
]
Enter fullscreen mode Exit fullscreen mode
  1. Rebind Alt + i/k/j/l to navigate in insert mode. Without it, you must exit insert mode before you can navigate. Additionally, Ctrl + k/i to move down/up intellisense menu.
[
  {
    "key": "capslock",
    "command": "extension.vim_escape",
    "when": "editorTextFocus && vim.active && !inDebugRepl"
  },
//allow movement while in insert mode
  {
    "key": "alt+j",
    "command": "cursorLeft",
    "when": "textInputFocus"
  },
  {
    "key": "alt+l",
    "command": "cursorRight",
    "when": "textInputFocus"
  },
  {
    "key": "alt+i",
    "command": "cursorUp",
    "when": "textInputFocus"
  },
  {
    "key": "alt+k",
    "command": "cursorDown",
    "when": "textInputFocus"
  },
//move down/up for intellisense menu
  {
    "key": "ctrl+k",
    "command": "selectNextSuggestion",
    "when": "suggestWidgetMultipleSuggestions && suggestWidgetVisible && textInputFocus"
  },
  {
    "key": "ctrl+i",
    "command": "selectPrevSuggestion",
    "when": "suggestWidgetMultipleSuggestions && suggestWidgetVisible && textInputFocus"
  },
  {
    "key": "ctrl+k",
    "command": "workbench.action.quickOpenSelectNext",
    "when": "inQuickOpen"
  },
  {
    "key": "ctrl+i",
    "command": "workbench.action.quickOpenSelectPrevious",
    "when": "inQuickOpen"
  },
//move down/up for other list menu
  {
    "key": "k",
    "command": "list.focusDown",
    "when": "listFocus && !inputFocus"
  },
  {
    "key": "i",
    "command": "list.focusUp",
    "when": "listFocus && !inputFocus"
  }
]
Enter fullscreen mode Exit fullscreen mode

This is my entire keybindings.json file. I recommended you copy/paste the whole file.
Repo

Top comments (0)