Make :Q! have the same functionality as :q! in vim

和自甴很熟 提交于 2020-02-13 11:36:14

问题


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 -bar argument 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!