linux版的vim中如何用快捷键进行与系统剪切板交互的复制粘贴?

时间:2022-03-20 08:23:16

就是剪切不存在buffer中,而是存在剪切板中;粘贴从剪切板粘贴。

#buffer 意思是缓冲器,指的应该是vim内寄存复制的东西的地方

#clipboard是剪切板,指的应该是系统中寄存复制的东西的地方


用vim这么久了,始终也不知道怎么在vim中使用系统粘贴板,通常要在网上复制一段代码都是先gedit打开文件,中键粘贴后关闭,然后再用vim打开编辑,真的不爽;上次论坛上有人问到了怎么在vim中使用系统粘贴板,印象里回复很多,有好几页的回复却没有解决问题,今天实在受不了了又在网上找办法,竟意外地找到了,贴出来分享一下。

如果只是想使用系统粘贴板的话直接在输入模式按Shift+Inset就可以了,下面讲一下vim的粘贴板的基础知识,有兴趣的可以看看,应该会有所收获的。
vim帮助文档里与粘贴板有关的内容如下:

   1. vim有12个粘贴板,分别是0、1、2、...、9、a、“、+;用:reg命令可以查看各个粘贴板里的内容。在vim中简单用y只是复制到“(双引号)粘贴板里,同样用p粘贴的也是这个粘贴板里的内容;

      
   2. 要将vim的内容复制到某个粘贴板,需要退出编辑模式,进入正常模式后,选择要复制的内容,然后按"Ny完成复制,其中N为粘贴板号(注意是按一下双引号然后按粘贴板号最后按y),例如要把内容复制到粘贴板a,选中内容后按"ay就可以了,有两点需要说明一下:
          * “号粘贴板(临时粘贴板)比较特殊,直接按y就复制到这个粘贴板中了,直接按p就粘贴这个粘贴板中的内容;
          * +号粘贴板是系统粘贴板,用"+y将内容复制到该粘贴板后可以使用Ctrl+V将其粘贴到其他文档(如firefox、gedit)中,同理,要把在其他地方用Ctrl+C或右键复制的内容复制到vim中,需要在正常模式下按"+p;

      
   3. 要将vim某个粘贴板里的内容粘贴进来,需要退出编辑模式,在正常模式按"Np,其中N为粘贴板号,如上所述,可以按"5p将5号粘贴板里的内容粘贴进来,也可以按"+p将系统全局粘贴板里的内容粘贴进来。

摘自:http://www.cnblogs.com/softwaretesting/archive/2011/07/12/2104434.html


   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%此为分割线%%%%%%%%%%%%%%%%%%%%%%%%%%%

源自:

http://www.zhihu.com/question/21203154


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%此为分割线%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%此为分割线%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%此为分割线%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%此为分割线%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%此为分割线%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%此为分割线%%%%%%%%%%%%%%%%%%%%%%%%%%%

这个问题我搞明白了