Navigating git diffs in VSCode with VSCodeVim
In Vim, ]c and [c jump to the next and previous git diff (c is for change). Unfortunately this is a keybinding I have memorized and cannot live without. The venerable Vim plugin for VSCode doesn't support this out of the box, but I managed to wire it up myself - it just took a bit more fiddling than I was expecting.
First I added this to settings.json:
"vim.normalModeKeyBindingsNonRecursive": [
{
"before": ["]", "c"],
"commands": ["workbench.action.editor.nextChange"]
},
{
"before": ["[", "c"],
"commands": ["workbench.action.editor.previousChange"]
}
]This works everywhere except for VSCode's diff viewer, which is sort of cursed. In the diff viewer, VSCodeVim just printed the command name at the bottom of the screen instead of executing it. I spent a while confused by this until Claude suggested that I open the Command Palette and search for "Go to Next Change" while in a diff editor. From here, I can open the little cog (I had never known what the little cog does) and look at the command being executed, which was workbench.action.compareEditor.nextChange, not workbench.action.editor.nextChange. Because VSCode is secretly terrible, this config isn't obviously available anywhere.
Since ]c and [c are already being captured by VSCodeVim, I couldn't bind the diff view versions in settings.json the same way. Instead, these worked when added to keybindings.json:
{
"key": "] c",
"command": "workbench.action.compareEditor.nextChange",
"when": "textCompareEditorVisible && vim.mode == 'Normal'"
},
{
"key": "[ c",
"command": "workbench.action.compareEditor.previousChange",
"when": "textCompareEditorVisible && vim.mode == 'Normal'"
}With these two sets of shortcuts in place, I could navigate between diffs in VSCode!