Search code examples
visual-studio-codevscodevim

VSCode + VSCodeVim undo key rebinding


VSCodeVim uses different undo stack and it annoys me when after undoing all the unsaved changes in vim undo stack, VSCode still shows that file is not saved. For that reason, I'd like to use VSCode's undo stack and map "u" to "Ctrl+z". My keybinding is following:

{
    "key": "u",
    "command": "undo",
    "when": "editorTextFocus && !editorReadonly && vim.active && vim.mode != 'Insert'" 
}

The problem is that even though I specified that it shouldn't work when vim mode is Insert it still undoes the last change and inserts 'u'. Can anyone suggest what is the correct way to rebind undo?


Solution

  • I tried the Doktor OSwaldo's proposal but for some reason it doesn't work. However I managed to find a solution:

    "vim.otherModesKeyBindingsNonRecursive": [ 
         { 
             "before": ["u"], 
             "after": [],
             "commands": [
                 {
                     "command": "undo", 
                     "args": []
                 }
             ] 
         } 
     ]