简体   繁体   中英

how to remap “q!” and “q” in vim

I'm trying to remap q and q! . Here's what I'm trying:

cnoremap q :call TabCloseLeft('q')
cnoremap q! :call TabCloseLeft('q!')

That properly remaps :q but doesn't capture :q! . I've read various help sections, but I'm obviously overlooking something.

I see some problems:

  • You are using a cnoremap dangerously eg /q
  • You are using trying to override vim's native :quit function
  • Looks like you are trying to force vim into a tab behavior

cnoremap

Do not use cnoremap to try and create commands, use :command . If you want to override a command then use a clever cabbrev expression or plugin. See vim change :x function to delete buffer instead of save & quit

Native quit

There are many ways for quiting a buffer in vim. Some do slightly different things. As vimmers learn more commands they integrate them into their workflow. eg <cw>c to close a split/window and ZZ to update and quite the current buffer. If you go down this path you will be overriding many command or you will be disregarding useful commands.

Tabs

Learn to use buffers effectively . Using tabs in Vim is great however they are not the only way and will certainly cause you pain down the road. IMHO it is best to curtail these behaviors and encourage better habits.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM