Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use capital Q also to quit Vim

Tags:

vim

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>
like image 464
Jikku Jose Avatar asked Apr 09 '14 15:04

Jikku Jose


People also ask

How do you exit a Vim file?

You can press the Esc key. Type SHIFT Z Z to save and exit. Type SHIFT Z Q to exit without saving.

How do I exit vi editor without saving?

In Vi, write means save, and quit means exit. If you've made mistakes along the way while editing and want to back out (abandon) all non-saved changes, enter Command mode by pressing Esc and typing :q! This command quits without saving any changes and exits Vi.


2 Answers

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.

like image 178
Ingo Karkat Avatar answered Sep 27 '22 20:09

Ingo Karkat


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

:command Q q
like image 27
Cody Avatar answered Sep 27 '22 20:09

Cody