根本的机制是osc52
osc52 is an ansi escape sequence that allows you to copy text into your system clipboard from anywhere, including from remote ssh sessions. check vim-oscyank, a plugin which integrates osc52 into vim.
xterm 支持osc52,但是需要打开allowwinndowops,方法是按住ctrl 鼠标右键,在vt font菜单里的最下面勾选allow window ops,或者在.xresources中添加下面两行(第二行是man tmux中有说明的):
xterm*allowwindowops:true
xterm*disallowedwindowops: 20,21,setxprop
然后运行:
xrdb ~/.xresources
使其生效。
如果还与tmux一起使用的话,在tmux的配制文件(.tmux.conf)中添加
set -s set-clipboard on
(上面的命令在cu上发不上来,只能截图了,各位看官海涵)
相对应的验证方式为(本机):
xsel -o --clipboard
xsel -o --primary
xsel -o --secondary
xterm的说明文档xterm control sequences描述如下
(链接也发不上来,再截图)
the first, pc, may contain zero or more characters from the
set c , p , q , s , 0 , 1 , 2 , 3 , 4 , 5 , 6 , and 7 . it is
used to construct a list of selection parameters for
clipboard, primary, secondary, select, or cut-buffers 0
through 7 respectively, in the order given. if the parameter
is empty, xterm uses s 0 , to specify the configurable
primary/clipboard selection and cut-buffer 0.
对linux(或者说x11)系统中三个剪贴板的说明如下(注1):
while os x and windows systems only support the "clipboard" buffer, x keeps three separate selection buffers:
the "clipboard" buffer, usually manipulated with ctrl-c / ctrl-v,
the "primary" buffer, typically used by highlighting text and middle-clicking to paste, and
the "secondary" buffer, which is rarely used.
注1:linux kernel不包含剪贴板子系统,这个功能是由x11提供的
在vim中使用osc52的功能需要安装一个插件vim-oscyank,地址如下:
h_t_t_p_s://github.com/ojroques/vim-oscyank
凯发app官方网站主页给的配制方式如下:
nmap c oscyankoperator
nmap cc c_
vmap c oscyankvisual
我把配制里面的c都改成了y,这样\yy就是通过oscyank的拷贝了
nmap y oscyankoperator
nmap yy y_
vmap y oscyankvisual
不加前导字符(leader)的y是普通拷贝,加了前导字符\的y是通过oscyank插件实现了osc52的(远程)拷贝。