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 splitctrl+j
: It will move your cursor to the Down editor pane from vertical splitctrl+k
: It will move your cursor to the Up editor pane from vertical splitspace+e
: Open/Close sidebarshift+l
: Open next tab in the editor group (You can also remap this totab
)shift+h
: Open previous tab in the editor group (You can also remap this toshift+tab
)space f f
: Show list of files in current projectspace ,
: show list of files that are open in the buffershift+j
: If you have visual selection line(s), move those selected lines one step downshift+k
: If you have visual selection line(s), move those selected lines one step upshift+k
: In normal mode show hover documentationspace c a
: code actionspace c r
: code referencespace c s
: go to symbolspace b d
: close active buffer/editorspace g d
: go to definitionspace g r
: go to referencesspace s g
: find in files (search ripgrep in neovim)space g g
: Gitctrl+n
: multi selection
File explorer mappings:
r
: rename file/foldery
/c
: yank/copy file/folderp
: paste file/folderx
: Cut file/folderd
: Delete file/foldera
: add new fileshift+a
: Add new folders
: Open current file to horizontal splitshift+s
: Open current file to vertical splitenter
: Open selected file (In Mac OS,enter
key opens rename action).
Hope you find this useful.