12

Tried using the following in my .vimrc, but somehow it isn't working. Also, is there any down sides to using "Q" also along side the usual q to quit the editor. Apparently, I find stumbling on this issue a lot, but don't see this tweak is most .vimrcs.

noremap Q :quit<CR>
Jikku Jose
  • 18,306
  • 11
  • 41
  • 61
  • 1
    Mapping seems to be fine. Are you getting any error? – Amit Apr 09 '14 at 15:43
  • 3
    May I introduce you to `ZZ` and `ZQ`, `:h ZZ` and `:h ZQ` – Peter Rincker Apr 09 '14 at 15:44
  • You're defining normal + visual + op-pending mappings. In neither does `q` quit Vim (rather, it starts / stops macro recording). Why you mean is `:q`, which is command-line mode. – Ingo Karkat Apr 09 '14 at 15:56
  • Thanks, for ZZ and ZQ. But somehow I :{q/Q} better as its more difficult to do and might help avoid typos. Also, I prefer not to change case for the command. – Jikku Jose Apr 09 '14 at 15:59

2 Answers2

14

If you want to quit Vim with :Q, a simple mapping won't do, because you then won't be able to type Q in the command-line (which is the mode you would have to map, using :cnoremap).

You can either just define an uppercase command:

:command! -bar -bang Q quit<bang>

or use the technique described in aliasing a command in vim, which also works for lower-case. Or have a look at cmdalias.vim - Create aliases for Vim commands.

Community
  • 1
  • 1
Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • Wow, it worked well! Quite a newbie to Vim, so still not clear with most of it. But have to admit, I am in love :) – Jikku Jose Apr 09 '14 at 16:04
10

If you want to quit vim with :Q just add this to your vimrc

:command Q q
Cody
  • 578
  • 3
  • 13