Disable for good VIM's number increment that is mapped to Ctrl-a

喜夏-厌秋 提交于 2019-12-19 04:07:21

问题


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


来源:https://stackoverflow.com/questions/36601789/disable-for-good-vims-number-increment-that-is-mapped-to-ctrl-a

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