':W undoes all my changes in Neovim. How do I turn this off?

I've checked mappings in Neovim but can't find any mapping to :W that would cause an 'undo all'. It's frustrating when I accidentally type :W instead of :w.

Where could I find this binding and how can I toggle it?



Solution 1:[1]

It's not a mapping, it's a command. Run :verbose command W to check what it does and where it's defined. It's not a default map in either vim or neovim, so it's probably a plugin (or potentially your Vim config file). Also worth noting that you can click tab to show all available options, and then :h :WhateverCommandNameYouFoundHere to find out what it's for, assuming it's related to a plugin that also documented it.

Vim has auto-resolution of partials, so if there's only one command starting with W (say WholeFile just to have an example), you can :W to reference that command. If, however, there's additionally a :Where, you need at least :Who for auto-resolution. Vim will complain about ambiguous user-defined commands, so odds are that there's a custom command somewhere.

See also: |:verbose|, specifically the bit that says:

When 'verbose' is non-zero, listing the value of a Vim option or a key map or
an abbreviation or a user-defined function or a command or a highlight group
or an autocommand will also display where it was last defined.  If it was
defined manually then there will be no "Last set" message.  When it was
defined while executing a function, user command or autocommand, the script in
which it was defined is reported.

Which generally means you can find commands, keybinds, Vim options, functions, highlight groups, or autocommands that were defined in files sourced when Vim started. This is really useful if you're trying to track stuff like this down.


More importantly, as you've already figured out, :verbose command W is also going to tell you the definition of the command. In your case specifically, it was entirely under your control, meaning you can remove it or rename it if you don't want it to conflict.

In general, if it's a part of a plugin (and you use a plugin manager), check with the plugin documentation to see if you can disable or rename it. If you can't, you can always |delcommand| - might need an autocmd to wait before running it since plugins are sourced after the config file, but it's an option nonetheless.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 desertnaut