在无clipboard 的vim 中, 如何使用系统剪切板

来源:互联网 发布:斯维尔是什么软件 编辑:程序博客网 时间:2024/05/17 03:22
--------------------------------------------------------------------------------
在无clipboard 的vim 中, 如何使用系统剪切板
--------------------------------------------------------------------------------
方法是,用鼠标选择。 一种是按住shift键选,一种是不用按shift键选。详见后述。

背景:
在.vimrc 中,有如下语句:
" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
   set mouse=a
endif

在vim帮助文件中,help mouse 发现了如下的解释:
The mouse can be enabled for different modes:
                n       Normal mode
                v       Visual mode
                i        Insert mode
                c       Command-line mode
                h       all previous modes when editing a help file
                a       all previous modes
                r       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 mouse for
modeless selection.  This doesn't move the text cursor.

这段代码很难理解透,看下面解释。
set mouse=a启动了所有模式, vim接管了鼠标的控制。好处是所有模式下 cursor 可以跟随鼠标点击。
并且copy/paste 可以由"*来处理。 但是,如果 "* 不能访问x-server, 即vim 没有 clipboard 功能, 则"* 无效。
gui 下的vim 通常有"*, 而控制台下往往没有。


由此知道鼠标事件有两种处理方式,vim 程序处理和 X 处理。
如果X负责处理,则是左键选择,中键粘贴。可以进行copy/paste

要在vim中由X负责处理,有两个方法:
1. 按住 shift 键,然后选择,此时由 X 处理该选择,copy 选项就 enable 了。如果放掉shift键,则由 vim 处理该选择。
2. 在 .vimrc 中设置 set mouse= (就是说清空),此时vim永远不再干涉鼠标选择,永远把处理权交给 X,
这个时候鼠标就处于无模式编辑状态, 当然vim中的编辑光标也不会跟随鼠标了。

由此我们总结了在无clipboard 中使用剪切板的两种方法。
1. 按住shift 键,鼠标选择。
2. 设置选项,关闭mouse, 再用鼠标选择。
很遗憾, 全文选择就不可能得到了。select all 也只是全屏选择。
0 0