问题
Sometimes in vim, I accidentally type :Q instead of :q in normal mode. To work around this, I've added this in my .vimrc:
command Q q
This works fine for :Q, but in case I type :Q!, vim responds with "No ! allowed". How do I make vim accept :Q! and interpret it as :q! ?
回答1:
:command -bang Q quit<bang>
For more information, see :help :command-bang.
回答2:
I prefer this for my commands
command! -bar -bang Q quit<bang>
- The bang on
:command!will allow to re-source your vimrc without errors, see:help E174 - The
-barargument will allow to concatenate further commands with |, see:help :command-bar <bang>expands to ! if one is used, see:help :command-bang
来源:https://stackoverflow.com/questions/5434742/make-q-have-the-same-functionality-as-q-in-vim