vim + COPY + mac over SSH

后端 未结 12 1199
悲哀的现实
悲哀的现实 2021-01-30 01:12

I access a sever over ssh on which I run vim for editing files. When I try to yank text from vim into an editor locally on my mac (lion) either with y OR \"+y it does not work.

相关标签:
12条回答
  • 2021-01-30 01:17

    Or, from the terminal, write less [filename] to get it written to the terminal. Then start byt selecting with your mouse, while you hold down-arrow-key down. Then you can select the whole bunch.

    0 讨论(0)
  • 2021-01-30 01:25

    To expand on Ray's answer…

    When you are using Vim on a remote server via SSH, everything you do in Vim is done on the remote server. The remote server and the remote Vim that you are running on it have zero practical knowledge of your local computer and its system clipboard.

    Because of that, y will never put the yanked text in your local clipboard.

    In order to copy a chunk of text from the remote Vim to your local machine's clipboard you have three options:

    • Select the text with your mouse and hit Cmd+C like in any Mac OS X application.

      Obviously, it seems to be the easiest but it has at least three limitations:

      1. It is limited to the current screen. If the text you want to yank is not displayed entirely you won't be able to copy all of it.

      2. It doesn't play well with set mouse=a. With this option, any attempt to select something with the mouse will result in a visual mode selection which can't be copied with Cmd+C. As a workaround, you can use Alt+mouse to select the text without entering visual mode or simply remove this setting from your remote ~/.vimrc.

      3. Line numbers are copied as well.

    • Put the yanked text in a temporary file, scp it to your local machine and use pbcopy to put it in your system clipboard.

      This solution seems to be a little convoluted but it works (and the problem itself is also a little bit convoluted). Over the years I've seen a lot of different implementations ranging from simple one liners to client/server setups. Here is one, feel free to google around for others.

    • Use X-forwarding to connect your local clipboard to the remote clipboard if available.

    0 讨论(0)
  • 2021-01-30 01:25

    Had this problem - log in from OSX over SSH to a linux box and cannot copy text from a file, opened with vim.

    My workaround is :set mouse=i

    By default mouse is enabled in all modes. When you set it to be enabled only in Insert mode you can scroll around and copy when you are not editing (normal mode) but when you start editing (by hitting the I or Insert key) and enter insert mode the mouse acts as cursor placement and you cannot copy from terminal.

    You can set that option in ~/.vimrc

    See :help mouse for more information about the values you can set and the modes.

    0 讨论(0)
  • 2021-01-30 01:25

    One trick which i use often during copying vim text using mouse if number of lines get little over-flown my screen is to minimize (Cmd + '-') the text. :) Minimize so much that you can not see by eyes but you can copy all the text in one go.

    0 讨论(0)
  • 2021-01-30 01:26

    iTerm2 Shell Utilities come with it2copy which allows copying from a remote server to a client clipboard. Install Shell Utilities on the remote server and make sure you have Applications in terminal may access clipboard checked.

    Then, go into visual mode, select the text and execute <,'>:w !it2copy

    0 讨论(0)
  • 2021-01-30 01:26

    Try the other clipboard register - "*y.

    0 讨论(0)
提交回复
热议问题