vim 中鼠标右键复制

来源:互联网 发布:水电预算软件下载 编辑:程序博客网 时间:2024/04/30 07:29
~/.vimrc中加入 set mouse=a 后,vim鼠标右键变得不能复制了,解决办法如下:

按住 shift 键,然后选择,此时表示由 X 处理该选择,copy 选项就 enable 了。如果放掉shift键,则由 vim处理该选择。


原文:

新修改了~/.vimrc 文件之后, 发现鼠标右健无法复制文本。

发现在配置文件(~/.vimrc)中发现,有这样一段话:
 
11 " In many terminal emulators the mouse worksjust fine, thus enable it.
 12 if has('mouse')
 13   set mouse=a
 14 endif

在vim帮助文件中发现了如下的解释:
The mouse can be enabled for different modes:
                    Normal mode
                    Visual mode
                     Insert mode
                    Command-line mode
                    all previous modes when editing a help file
                    all previous modes
                    for |hit-enter| and |more-prompt| prompt
Normally you would enable the mouse in all four modes with:
               :set mouse=a
When the mouse is not enabled, the GUI will still use the mousefor
modeless selection.  This doesn't move the textcursor.

所以配置文件中的set mouse=a启动了所有模式, vim接管了鼠标的控制。

其中涉及的背景知识是:

鼠标事件有两种处理方式,程序处理和 X 处理。

如果 X 负责处理,则是左键选择,中间粘贴。

要让 vim 中由 X 负责处理,有两个方法:

1. 按住 shift 键,然后选择,此时由 X 处理该选择,copy 选项就 enable 了。如果放掉shift键,则由 vim处理该选择。
2. 在 .vimrc 中设置 set mouse= (就是说清空),此时vim永远不再干涉鼠标选择,永远把处理权交给X,这个时候鼠标就处于无模式编辑状态, 当然也能用鼠标来切换vim里面的tab窗口了,vim中的编辑光标也不会跟随鼠标了。
 
grep/vimgrep后的显示结果list:
:copen
:cclose
:cwindow
:cl
:cn
:cp
  
:help quickfix.txt
原创粉丝点击