mac 下 ssh Linux 后 vim 文字如何复制到本地 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
qanniu
V2EX    macOS

mac 下 ssh Linux 后 vim 文字如何复制到本地

  •  
  •   qanniu 2021 年 8 月 21 日 3521 次点击
    这是一个创建于 1707 天前的主题,其中的信息可能已经有所发展或是发生改变。

    似乎没有什么优美的方法。 目前用 option 键 workaround, 大家有更优美的方法吗?

    15 条回复    2021-09-22 17:20:12 +08:00
    Tiande
        1
    Tiande  
    PRO
       2021 年 8 月 21 日
    复制到临时文档里,再 sftp 出来
    Tiande
        2
    Tiande  
    PRO
       2021 年 8 月 21 日
    用带编辑功能的 sftp 工具应该是比较省事的方案
    creanme
        3
    creanme  
       2021 年 8 月 21 日
    先保存退出再 cat 然后复制到本地剪切板?
    AllenHua
        4
    AllenHua  
       2021 年 8 月 21 日
    我日常的习惯就是上面三楼的结合体

    行数不多的话直接 cat 出来 然后选中 Command + C 拷贝

    行数很多的话 你可以标准输出到另一个文件然后通过 scp samba 或者 ftp sftp 拷贝到本机

    cat xxx.conf > /mnt/disk/path/abc.txt

    然后再将 abc.txt 移动到本地
    hronro
        5
    hronro  
       2021 年 8 月 21 日
    用 Alacritty 的 Vim mode 复制
    lucifer9
        6
    lucifer9  
       2021 年 8 月 21 日 via iPhone   1
    osc52 ?
    Kobayashi
        7
    Kobayashi  
       2021 年 8 月 21 日 via Android
    - osc52 https://github.com/ojroques/vim-oscyank
    - 或者开 SSH X Forwarding 同步剪贴板,需要 vim 开启 clipboard 特性
    FurN1
        8
    FurN1  
       2021 年 8 月 21 日
    我的方案。

    Vim 和剪贴板有关的配置
    https://github.com/g6ai/dotfiles/blob/902cce75199f33cfed68e68bce141d716827f4e8/vim/vimrc#L154-L177

    tmux 通过 SSH 的复制(我写了个 wiki,里面有配置细节和配置文件链接)
    https://github.com/g6ai/dotfiles/wiki/tmux.conf#copy-over-ssh

    比较正统(优雅)的方式是通过 SSH 本身来 forward 内容。我在 wiki 这一节写了细节:
    https://github.com/g6ai/dotfiles/wiki/tmux.conf#helper-scripts
    大概就是通过设置合适的$DISPLAY 环境变量,让 SSH 搞清楚正确的 X sssion 。在 tmux 里这一步需要手动做。用 tmux 不好的地方是设置起来稍微麻烦(不过你用我的配置就一劳永逸,而且用任何 terminal 都一样)。在 tmux 之外通过 SSH 复制内容,取决于你的 terminal emulator 对于 X11 forwarding 是否有好的支持,比如楼上提到的 Alacritty 有自己的方法。

    大前提是你用的是 X11 。如果是用的比较新的 Wayland,那一切原理都不一样了。
    FurN1
        9
    FurN1  
       2021 年 8 月 21 日
    @IgniteWhite 补充:在 ssh config 里面要开启 X11 Forwarding
    jdhao
        10
    jdhao  
       2021 年 8 月 21 日 via Android
    @Kobayashi 用 osc52 应该是最方便的了,不过要注意你的 terminal 是否支持,kitty 和 iterm2 应该是支持的
    archean
        11
    archean  
       2021 年 8 月 22 日 via iPhone
    难道不是…直接拿鼠标选中,Command+C 就完了吗?
    AndyZhuAZ
        12
    AndyZhuAZ  
       2021 年 8 月 22 日
    复制粘贴不是可以用的吗?
    gesse
        13
    gesse  
       2021 年 8 月 24 日
    cat <<EOF >>~/.vimrc

    if has('mouse')
    set mouse=r
    endif

    EOF
    qanniu
        14
    qanniu  
    OP
       2021 年 8 月 24 日
    @gesse
    谢谢, 这是我个人觉得最无痕的方法.
    但没明白` r for hit-enter and more-prompt prompt` 含义

    ```
    'mouse' string (default "", "a" for GUI, MS-DOS and Win32,
    set to "a" in defaults.vim)
    global
    {not in Vi}
    Enable the use of the mouse. Only works for certain terminals
    (xterm, MS-DOS, Win32 win32-mouse, QNX pterm, *BSD console with
    sysmouse and Linux console with gpm). For using the mouse in the
    GUI, see gui-mouse.
    The mouse can be enabled for different modes:
    n Normal mode and Terminal modes
    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.
    See mouse-using. Also see 'clipboard'.
    Note: When enabling the mouse in a terminal, copy/paste will use the
    "* register if there is access to an X-server. The xterm handling of
    the mouse buttons can still be used by keeping the shift key pressed.
    Also see the 'clipboard' option.
    ```
    aec4d
        15
    aec4d  
       2021 年 9 月 22 日
    OSC52 应该是我用过最好的方法

    远程
    sudo dd of=/usr/local/bin/osc52 <<'EOF'
    #!/bin/bash
    printf "\033]52;c;$(base64 | tr -d '\r\n')\a"
    EOF
    sudo chmod +x /usr/local/bin/osc52

    本地对 iterm2 和 tmux 开启 osc52 支持
    set -g set-clipboard on
    远程 cat file | osc52 就可以了
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2861 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 61ms UTC 12:00 PVG 20:00 LAX 05:00 JFK 08:00
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86