5

When typing fast, sometimes the :q is taken as :Q and it is annoying when you have to repeat that for twice or thrice before actually quitting the Vim session.

Is there a way to make :Q to :q to overcome the above said problem ?

5

Instead of mapping or abbreviating, I would use a custom command to actually create a new behavior for this edge-case:

 command! Q :q

Now you can use :Q to have the same effect as :q, without any risk of overriding any function name/other mapping.

You can then define other command depending on your usage, adding a !, using W ...


Also worth knowing, as a workaround, to map ; to : and : to ;. This make the command line accessible without having to press the shift key, thus preventing the :Q to arise.

nnoremap ; :
nnoremap : ;
  • The map ; to : may create some confusion if you have your muscle memory tuned to the shift + : – North May 19 '16 at 8:59
  • Of course, I wouldn't recommand it either, but some people do use it: youtube.com/watch?v=aHm36-na4-4 – nobe4 May 19 '16 at 9:01
-3

You can use command abbreviation for it.

 :cabbr Q q

Put this in ~/.vimrc file.

Whenever you type :Q, it will be automatically converted to :q and file will be exited. Similarly, you can use abbreviations like

 :cabbr W! w!
 :cabbr wQ wq

as well.

  • Edit : same works for :W to :w but my airline appearance changes when I do :W instead of :w – North May 19 '16 at 6:08
  • For someone who might want to work with Qt more, that can pose a problem. – North May 19 '16 at 6:21
  • If you have function names starting with W or Q also, it shouldn't be a problem. Our abbreviation works only when you type a space or a enter after W or Q. For function starting with Q or W, the next character will be a alphabet and not a space. So, it won't be a problem. – SibiCoder May 19 '16 at 6:25
  • 3
    If you have function names starting with W or Q also, it shouldn't be a problem. - Really? These guys must be thoroughly confused then. :) – Sato Katsura May 19 '16 at 7:01
  • 1
    Try this: :cabbr Q q, then :r Q. Then again, I suppose you'll tell me this isn't a problem either, because you're working on Windows, where filenames are case-insensitive. :) – Sato Katsura May 19 '16 at 7:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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