1

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.

Daniel Convissor
  • 323
  • 2
  • 12
  • what are you trying to do with the mappings? this will put the `:call Tab...` text in your command line when you pressed `q` there. what do you mean `desn't capture :q!` ? it should work. – Kent Apr 23 '14 at 13:32
  • Not very clear about your question, but might give you some hint. Since "q" and "q!" begins with the same character "q", vim will wait about 1 second for you after you type "q", if you don't type another character, it will use the first "q" map. – LotAbout Apr 23 '14 at 13:33
  • @LotAbout default is `1000ms` could be customized by setting options `to, tm` – Kent Apr 23 '14 at 13:38

1 Answers1

5

I see some problems:

  • You are using a cnoremap dangerously e.g. /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. e.g. <c-w>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.

Community
  • 1
  • 1
Peter Rincker
  • 43,539
  • 9
  • 74
  • 101
  • One addition: [bang is properly a command modifier, not part of the command name](http://vimdoc.sourceforge.net/htmldoc/map.html#:command-bang), you can e.g. `:command -bang QT etc` to define a `QT` command that takes optional `!`. – jthill Apr 23 '14 at 15:08