MacOS – How to mouse copy a very long line in vim terminal OS X

copy/pastemacosmouseterminalvi

I want to copy with mouse one line from one vim terminal to another vim terminal. This line is huge and has a hidden character (I presume at the beginning) that I do not want to copy.

In other words: I want to copy from the first character I consider good to the last character I consider good too. The problem is the copy with mouse does not go to the end of the line because this line is huge. It goes only to the end of the terminal.

The question is, how can I copy with mouse from character A to character B that is not visible on the terminal?

BTW these characters are a series of visible @. One per line on many lines. Using the arrow key there is only 2 lines with these @ in the middle. This shows between the first real line and the second real line.

Best Answer

You can use a little trick: save that long line to a temp file and copy that.

  1. Select the desired portion of the line by moving the cursor to the first good position. By pressing v f [character], you select everything from that position to the next occurence of [character]. Pressing v $ would select to the end of that line. Use the power of Vim to select just the portion of the text you need.
  2. Write the selection to a temp file by typing :w /tmp/long_line.
    If the command already starts with :'<,'>, that's fine (it's a mark for your selection), just type ahead: :'<,'>w /tmp/long_line
  3. Exit Vim and process the /tmp/long_line file as you like. A simple solution would be cat /tmp/long_line and selecting the output

Alternative: Buy a larger screen ;)