Disable for good VIM's number increment that i

2019-02-15 11:38发布

问题:

I am using local and remote tmux sessions. To send commands to the local tmux I use Ctrl-a, and to the remote Ctrl-q. I have tried to disable the number increment that normally executes with Ctrl-a in vim, but it now triggers with Ctrl-q and i cannot find a way to disable it. BTW this happens only when a particular tmux window does not nest a remote one. Also, I think there still might be a combination of shortcuts in a remote tmux session that also triggers the increment.

So is there a way to completely disable the function? An ideal solution would be to override it with a function that does nothing. That's a very sneaky command, and I had some really terrible debugging experiences in the past because of this!

My tmux.conf:

..
unbind C-b
set -g prefix C-a
bind-key -n C-q send-prefix
...

Then in vim I try to disable both Ctrl-a and Ctrl-q with no-ops.

This is my vimrc:

...
map <Ctrl-A> <Nop>
map <Ctrl-Q> <Nop>
...

I have also tried putting entries for Ctrl-a and Ctrl-q but still Ctrl-q does the increment. I think the problem is because tmux receives Ctrl-q and then sends it as prefix which is somehow not caught by my extra mappings.

Cheers, Paschalis

回答1:

Why it doesn't work

Ctrl is not a vim-recognized <> notation to represent a keyboard's Control key.

Recommendation

To disable Control-a triggering default vim auto-increment on a number:

  1. In your ~/.vimrc, as @Marth said, use <C-a>:

    map <C-a> <Nop>
    
  2. Save :w

  3. :so ~/.vimrc for it to take effect.

Warranty

  • Tested to work in Vim 7.4
  • You don't need to disable Ctrl-q in Vim

Explanation

  • Don't need to disable Ctrl-q within Vim, since your Tmux is never sending Ctrl-q,
  • Your posted tmux.conf is sending prefix, which you define as Ctrl-a, so Vim is only receiving Ctrl-a

Thus you successfully disable the auto-increment when you map Control-a to the do-nothing instruction <Nop>

Further reading

  • Vim, :help <>


标签: vim tmux