zoukankan      html  css  js  c++  java
  • linux与windows共享剪贴板(clipboard)

    linux与windows共享剪贴板(clipboard)的方法

    先说两句废话,其实linux和windows之间不需要共享剪贴板,直接在putty中,按住SHIFT+鼠标选择就可以了。

    但是作为一种hack行为或者不用鼠标实现复制功能,就需要这种方法了。

    组合:

    putty+tmux+vim+mobaiterm/xserver

    如果熟悉的朋友应该早已经用习惯了前面三个软件,号称三剑客。

    后面的两个软件只是使用其中的一部分功能,即x window的剪贴板。

    xserver是指windows这边的显示器,client是linux那边的程序向server发送图像数据,请求在xserver这里显示它的窗口,而不是在它原来的那个窗口显示。

    配置:

    putty:

    配置如下图所示的,打开Enable X11forwarding,并且填入X display location的值:127.0.0.1:0

    这里的127.0.0.1是指xserver的ip地址,:0是指那个显示窗口,在x window概念中,多用户系统,所以可以显示多个不同的窗口,:0一般是默认窗口。

    如果是使用cygwin或者其它一些ssh-agent连接,可以添加ssh -X user@linux_ip_address方式添加X11forwarding方法。

    图1

    tmux:

    在tmux的配置文件.tmux.conf中,要添加下面的代码:

    #Copy tmux paste buffer to CLIPBOARD(CLIPBOARD selection integration)
    #must install xclip and xsel
    bind C-c run "tmux save-buffer - | xclip -i -selection clipboard"
    #Copy CLIPBOARD to tmux paste buffer and paste tmux paste buffer
    bind C-v run "tmux set-buffer -- "$(xclip -o -selection clipboard)"; tmux paste-buffer"
    

    它的意思是,当执行ctrl+a,ctrl+c时,把tmux中的buffer添加到linux系统的剪贴板中,ctrl+a,ctrl+v则是输出linux系统的剪贴板内容。

    vim:

    在vim中,添加

    set guioptions+=aA       " get some autoselect interaction with the system clipboard

    这个是应用在vim gui中的,命令行中的vim无效

    mobaiterm/xserver

    在这里,mobaiterm和xserver中的xming是一个功能,就是它们提供了,把linux的剪贴板放到windows系统的剪贴板中,这只是一个小的功能,其实xserver还可以做很多其它的事情,我尝试过,是一种特别的概念。

    使用:

    现在就需要的是在tmux中,用tmux复制一部分文档,ctrl+[进入选中状态,然后按空格<space>,使用vim的上下左右移动光标选择文字,所使用<Enter>复制到tmux中,然后按Ctrl+a,ctrl+c复制到系统中的剪贴板clipboard中,然后在windows下的编辑器中,粘贴,就可以粘贴到刚刚tmux选择的文字。

    如果想让vim中复制的内容放到windows中,使用"+y把内容放到系统的剪贴板中,然后就可以复制到windows中了。

    参考(扩展阅读):

    How to copy from tmux running in putty to windows clipbard: http://stackoverflow.com/questions/17255031/how-to-copy-from-tmux-running-in-putty-to-windows-clipbard

  • 相关阅读:
    NoSQL数据库 continue posting...
    CAP 理论
    Clojure Web 开发 (一)
    HttpClient 4.0.x Tips
    zZ Java中String和Byte[]之间的那些事
    使用nhibernate出现Could not find the dialect in the configuration
    eclipse导入项目出现Project has no default.properties file! Edit the project properties to set one.
    今天开通此博~
    美国白蛾入侵北京 GIS兵法破解危局
    HTML5 存取Json
  • 原文地址:https://www.cnblogs.com/vastiny/p/4234735.html
Copyright © 2011-2022 走看看