VSCodeVim / VSCodeVim/Vim

`<C-z>` cannot be remapped from VSCode's undo functionality

Open
#7,164 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

area/remap
Dominant language
TypeScript
Stars
15.2k
Forks
1.5k
Avg merge
3d 18h
Merged PRs (30d)
6

Description

Immediate disclaimer: I've read through both https://github.com/VSCodeVim/Vim/issues/1490 and https://github.com/VSCodeVim/Vim/issues/6958, and want to be clear that this issue takes a different angle.

I understand that the advice regarding the disparity between VSCode's undo stack and VSCodeVim's, is that you must choose one or the other. Mixing the two is where previous confusion seems to have arisen from. Choosing to go with VSCode's undo stack requires remaps such as:

"vim.normalModeKeyBindingsNonRecursive": [
  // Use VSCode's undo stack
  { "before": ["u"], "commands": ["undo"] },
  { "before": ["U"], "commands": ["redo"] },
  { "before": ["<C-r>"], "commands": ["redo"] },
  { "before": ["<C-y>"], "commands": ["redo"] }
]

These will assign Vim and VSCode history keybindings to VSCode's undo functionality alone. That's all fine. The alternative is to fully adopt the undo stack implemented by VSCodeVim, which means using the default functionality built into u and <C-r>, with no translation layer required.

The issue I am raising relates to something @johnfn said back in 2017, where he referred to leaving ctrl-z totally alone, regardless of whether the user is using VSCode's undo stack or Vim's:

So rather than risk that 1% possibility, we just leave in the ctrl-z/y behavior, so that if we do screw up, you can still use them.

The sentiment of treating ctrl-z/y as failsafes to fall back on is fine, it's just that the reverse of the configuration mentioned earlier doesn't seem to be possible. In my particular case, I am wanting to have ctrl-y and ctrl-z duplicate the VSCodeVim functionality of <C-r> and u, such that I totally remove any trace of VSCode's undo stack, and go 100% with the VSCodeVim implementation. I personally use both u/<C-r> and the Windows style ctrl-z, ctrl-y when editing, depending on whether I'm holding the mouse, just like you would if using regular Vim with mswin.vim. For that reason I need both keybinding pairs to do the same thing.

But the problem is that ctrl-z doesn't seem to be freely remappable as is the case for ctrl-y. To prove this, try apply these simple remaps:

"vim.normalModeKeyBindingsNonRecursive": [
  // Have <C-z> comment the line, for testing purposes
  { "before": ["<C-z>"], "commands": ["editor.action.commentLine"] },

  // Have U call VSCodeVim's redo command
  { "before": ["U"], "after": ["<C-r>"] },

  // Have <C-y> call VSCodeVim's redo command
  { "before": ["<C-y>"], "after": ["<C-r>"] },
]

The last two remaps work fine, and of particular note is that <C-y> to <C-r> works as expected. Despite this being one of the keys that was supposedly left alone, it can clearly be remapped anyway. So with the above, U and <C-y> will both redo according to VSCodeVim's history. That's great. The problem is that the <C-z> remap doesn't work at all. Even after setting { "key": "ctrl+z", "command": "-undo" }, in keybindings.json, ensuring useCtrlKeys is true, and setting handleKeys as true for ctrl+z, the command does nothing.

The end goal is { "before": ["<C-z>"], "commands": ["u"] },, but at the moment, I can't get ctrl-z to do anything useful when delegating its handling to VSCodeVim.

Is ctrl-z truly ignored in its entirety by VSCodeVim? If so, this is a request for ctrl-z to be treated the same as ctrl-y: leave the two shortcuts there as defaults, but allow both to be remapped through the extension. At the moment, only ctrl-y is working as expected when remapped.

  • Extension (VsCodeVim) version: 1.21.8
  • VSCode version: 1.61.0
  • OS: Kubuntu

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the settings from the issue, especially the ctrl+z and ctrl+y mappings, with useCtrlKeys and handleKeys enabled. Trace the extension's keybinding handling for ctrl+z and compare it with ctrl+y. Done means ctrl+z can be remapped to VSCodeVim's undo behavior like ctrl+y can, with regression coverage for the reported configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript, vscode
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.