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?
Asked
Active
Viewed 262 times
1
ChocolateOverflow
- 677
- 1
- 6
- 15
1 Answers
2
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
Kiteration
- 240
- 1
- 8
xafter I wrote the answer. I'm still training myself to use it... It is the best solution. Is there, however, a way to remapqwtowqin command-line mode without knock-on effects? – Kiteration Feb 08 '22 at 13:09:cnoreabrrev <expr> qw getcmdtype() is# ':' && getcmdline() =~# '^\s*qw' ? 'wq' : 'qw'– D. Ben Knoble Feb 08 '22 at 15:54