1

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 1

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

2
  • 1
    Yes, 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 remap qw to wq in command-line mode without knock-on effects?
    – Kiteration
    Commented Feb 8, 2022 at 13:09
  • 2
    How about the classic :cnoreabrrev <expr> qw getcmdtype() is# ':' && getcmdline() =~# '^\s*qw' ? 'wq' : 'qw'
    – D. Ben Knoble
    Commented Feb 8, 2022 at 15:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.