The reason why the approach using user commands (with
:command!) does not work is that user commands are quite restricted in how they are allowed. They must always start with an uppercase letter (so they don't clash with Vim native commands) and their names may not include special characters (such as
Instead of user commands, you can use
:cabbrev to create an abbreviation that turns
wq in the command-line.
A naive approach using
cabbrev w< wq
The problem with this approach is that it will trigger if the word
w< is found in later parts of the command-line (not just at the beginning, as a command.) It will also trigger for other features that use the last line for input and also expand
cabbrev. One significant example of the latter is search, so if you search for
w< Vim might expand it to
wq (if it appears on its own, since abbreviations only trigger when the left-hand expression is a word on its own.)
In order to prevent those, you can use an
<expr> mapping, together with the
getcmdpos(), to ensure the
w< abbreviation only triggers when typed on an Ex command-line (entered through
:) and when it's typed at the beginning of the command (cursor position will be 3 after typing it, which is one more than the length of the expression.)
You can accomplish that with:
cabbrev <expr> w< getcmdtype() == ':' && getcmdpos() == 3 ? 'wq' : 'w<'
Note that the expression expands to
w< when the conditions don't hold. That's so that
w< will have no effect (by mapping to itself) in those cases.