I often mistype :wq
as :qw
. I can't create a command for qw
though since it doesn't start with an uppercase character. Is there a way I can bind qw
to wq
?
1 Answer
You can enter the command :cmap qw wq
. Entering it in as a command will set it for you current session. Put it as a line in your .vimrc
if you want it to be permanent.
A bit of explanation: cmap
means create a mapping for command-line mode, which will transform the left expression into the right one after you press enter <CR>
in the vim command-line (things you type after the colon :
)
See :help map
and section 40 of the user manual. http://vimdoc.sourceforge.net/htmldoc/usr_40.html
-
1Yes, I thought of
x
after I wrote the answer. I'm still training myself to use it... It is the best solution. Is there, however, a way to remapqw
towq
in command-line mode without knock-on effects? Commented Feb 8, 2022 at 13:09 -
2How about the classic
:cnoreabrrev <expr> qw getcmdtype() is# ':' && getcmdline() =~# '^\s*qw' ? 'wq' : 'qw'
– D. Ben Knoble ♦Commented Feb 8, 2022 at 15:54