Remap VScode keybinds to match with neovim

If you constantly switch between vscode and neovim (I am using lazyvim for my neovim config), then you might feel uncomfortable with different keybinds being used in different editor and your muscle memory will try to use vscode as a neovim but it do not work.

Here are the common keybinds that I use in neovim and I am remapping vscode to use the same.

Prerequisite

Install https://marketplace.visualstudio.com/items?itemName=vscodevim.vim plugin in your vscode, because all of the configs we are doing today depends on this plugin.

Setup steps

Lets open the user keybinds.json file in the vscode. For me it is located in ~/.config/Code/User/keybinds.json.

# keybinds.json
[
  {
    "key": "ctrl-h",
    "command": "workbench.action.navigateLeft",
  },
  {
    "key": "ctrl-l",
    "command": "workbench.action.navigateRight",
  },
  {
    "key": "ctrl-j",
    "command": "workbench.action.navigateDown",
  },
  {
    "key": "ctrl-k",
    "command": "workbench.action.navigateUp",
  },
  {
    "key": "space e",
    "command": "workbench.action.toggleSidebarVisibility",
    "when": "vim.mode == 'Normal' && (editorTextFocus || !inputFocus)"
  },
  {
    "key": "shift-l",
    "command": "workbench.action.nextEditorInGroup",
    "when": "(vim.mode == 'Normal' || vim.mode == 'Visual') && (editorTextFocus || !inputFocus)"
  },
  {
    "key": "shift-h",
    "command": "workbench.action.previousEditorInGroup",
    "when": "(vim.mode == 'Normal' || vim.mode == 'Visual') && (editorTextFocus || !inputFocus)"
  },
  {
    "key": "space f f",
    "command": "workbench.action.quickOpen",
    "when": "vim.mode == 'Normal' && (editorTextFocus || !inputFocus)"
  },
  {
    "key": "space ,",
    "command": "workbench.action.showAllEditors",
    "when": "vim.mode == 'Normal' && (editorTextFocus || !inputFocus)"
  },

  // Coding
  {
    "key": "shift-j",
    "command": "editor.action.moveLinesDownAction",
    "when": "vim.mode != 'Insert' && editorTextFocus"
  },
  {
    "key": "shift-k",
    "command": "editor.action.moveLinesUpAction",
    "when": "vim.mode != 'Insert' && editorTextFocus"
  },
  {
    "key": "shift-k",
    "command": "editor.action.showHover",
    "when": "vim.mode == 'Normal' && editorTextFocus"
  },
  {
    "key": "space c a",
    "command": "editor.action.codeAction",
    "when": "vim.mode == 'Normal' && editorTextFocus"
  },
  {
    "key": "space c r",
    "command": "editor.action.rename",
    "when": "vim.mode == 'Normal' && editorTextFocus"
  },
  {
    "key": "space c s",
    "command": "workbench.action.gotoSymbol",
    "when": "vim.mode == 'Normal' && editorTextFocus"
  },
  {
    "key": "space b d",
    "command": "workbench.action.closeActiveEditor",
    "when": "vim.mode == 'Normal' && editorTextFocus"
  },
  {
    "key": "space g d",
    "command": "editor.action.revealDefinition",
    "when": "vim.mode == 'Normal' && editorTextFocus"
  },
  {
    "key": "space g r",
    "command": "editor.action.goToReferences",
    "when": "vim.mode == 'Normal' && editorTextFocus"
  },
  {
    "key": "space s g",
    "command": "workbench.action.findInFiles",
    "when": "vim.mode == 'Normal' && (editorTextFocus || !inputFocus)"
  },
  {
    "key": "space g g",
    "command": "workbench.view.scm",
    "when": "vim.mode == 'Normal' && (editorTextFocus || !inputFocus)"
  },
  {
    "key": "ctrl-n",
    "command": "editor.action.addSelectionToNextFindMatch",
    "when": "(vim.mode == 'Normal' || vim.mode == 'Visual') && (editorTextFocus || !inputFocus)"
  },

  // File Explorer
  {
    "key": "r",
    "command": "renameFile",
    "when": "filesExplorerFocus && foldersViewVisible && !explorerResourceIsRoot && !explorerResourceReadonly && !inputFocus"
  },
  {
    "key": "y",
    "command": "filesExplorer.copy",
    "when": "filesExplorerFocus && foldersViewVisible && !explorerResourceIsRoot && !explorerResourceReadonly && !inputFocus"
  },
  {
    "key": "c",
    "command": "filesExplorer.copy",
    "when": "filesExplorerFocus && foldersViewVisible && !explorerResourceIsRoot && !explorerResourceReadonly && !inputFocus"
  },
  {
    "key": "x",
    "command": "filesExplorer.cut",
    "when": "filesExplorerFocus && foldersViewVisible && !explorerResourceIsRoot && !explorerResourceReadonly && !inputFocus"
  },
  {
    "key": "p",
    "command": "filesExplorer.paste",
    "when": "filesExplorerFocus && foldersViewVisible && !explorerResourceIsRoot && !explorerResourceReadonly && !inputFocus"
  },
  {
    "key": "d",
    "command": "deleteFile",
    "when": "filesExplorerFocus && foldersViewVisible && !explorerResourceIsRoot && !explorerResourceReadonly && !inputFocus"
  },
  {
    "key": "a",
    "command": "explorer.newFile",
    "when": "filesExplorerFocus && foldersViewVisible && !explorerResourceIsRoot && !explorerResourceReadonly && !inputFocus"
  },
  {
    "key": "shift-a",
    "command": "explorer.newFolder",
    "when": "filesExplorerFocus && foldersViewVisible && !explorerResourceIsRoot && !explorerResourceReadonly && !inputFocus"
  },
  {
    "key": "s",
    "command": "explorer.openToSide",
    "when": "filesExplorerFocus && foldersViewVisible && !explorerResourceIsRoot && !explorerResourceReadonly && !inputFocus"
  },
  {
    "key": "shift+s",
    "command": "runCommands",
    "when": "filesExplorerFocus && foldersViewVisible && !explorerResourceIsRoot && !explorerResourceReadonly && !inputFocus",
    "args": {
      "commands": [
        "workbench.action.splitEditorDown",
        "explorer.openAndPassFocus",
        "workbench.action.closeOtherEditors"
      ]
    }
  },
  {
    "key": "enter",
    "command": "explorer.openAndPassFocus",
    "when": "filesExplorerFocus && foldersViewVisible && !explorerResourceIsRoot && !explorerResourceReadonly && !inputFocus",
  },
]

Keybinds Summary

  • ctrl+h: It will move your cursor to the Left editor pane from horizontal split.

  • ctrl+l: It will move your cursor to the Right editor pane from horizontal split

  • ctrl+j: It will move your cursor to the Down editor pane from vertical split

  • ctrl+k: It will move your cursor to the Up editor pane from vertical split

  • space+e: Open/Close sidebar

  • shift+l: Open next tab in the editor group (You can also remap this to tab)

  • shift+h: Open previous tab in the editor group (You can also remap this to shift+tab)

  • space f f: Show list of files in current project

  • space ,: show list of files that are open in the buffer

  • shift+j: If you have visual selection line(s), move those selected lines one step down

  • shift+k: If you have visual selection line(s), move those selected lines one step up

  • shift+k: In normal mode show hover documentation

  • space c a: code action

  • space c r: code reference

  • space c s: go to symbol

  • space b d: close active buffer/editor

  • space g d: go to definition

  • space g r: go to references

  • space s g: find in files (search ripgrep in neovim)

  • space g g: Git

  • ctrl+n: multi selection

File explorer mappings:

  • r: rename file/folder

  • y / c: yank/copy file/folder

  • p: paste file/folder

  • x: Cut file/folder

  • d: Delete file/folder

  • a: add new file

  • shift+a: Add new folder

  • s: Open current file to horizontal split

  • shift+s: Open current file to vertical split

  • enter: Open selected file (In Mac OS, enter key opens rename action).

Hope you find this useful.