Sometimes I want to copy some content on remote host in vim, which will last for more than 1 page. But when clicked with left-click-button of mouse, and scrolling down, I find I was stuck at the first page.

I know I can use scp or first cat file then select.

But is there a way to enable mouse scrolling to do such a selection in vim?


Try :set mouse=a, should be what you're looking for.

Edit: As a side note, when you try to scroll through the file (as in two-finger scroll on a touchpad, for example), the text may not highlight as you'd expect. However, if you click where you want to start, then simply drag the mouse down, then everything should highlight as the mouse moves and the page should scroll down automatically as well.

  • cool ....... (+1) – JJoao Mar 3 '15 at 11:59
  • I tried that before, but actually, you can't copy the selected content, they are in visual mode – Zen Mar 3 '15 at 12:10
  • 2
    you can yank them to your clipboard, but on remote host this can't reach your purpose, either – Zen Mar 3 '15 at 12:11
  • @Zen, please see my rewritten answer. – JJoao Mar 5 '15 at 12:12

Without using mouse you can select lines in Vim.

Get out of insert mode, hit one of the options below, and then move up or down a few lines. You should see the selected text highlighted.

V       - selects entire lines 
v       - selects range of text
ctrl-v  - selects columns
gv      - reselect block

After selecting the text, try d to delete, or y to copy, or :s/match/replace/, or :center, or !sort.

  • cool! see also "+y (+1) – JJoao Mar 3 '15 at 12:00
  • 3
    yes, I know I can select that, but how could I copy these selected lines from remote host to my local clipboard? – Zen Mar 3 '15 at 12:14
  • +1 @Zen This is the same issue I have. I can copy & paste text within vim using Visual Selection, but have not been able to figure out how to export vim's selection to my local clipboard. – John T Dec 4 '18 at 20:25

X11 Clipboards

In X11 there are 2 independent clibpoards:

  • primary (paste with the midle buttom) (in vim -- register "*)
  • clipboard (paste with (CTR+V) or similar; like windows) (in vim -- register "+)

Vim + X11 Clipboards

The association between "+ "* and the systems clipboards needs a vim with +clipboard (see vim --version for the active option).

"+ is the vim register for the system clipboard (CTR-C / CTR-V or similar).

Using @grish and @serenesat we can select some visual text, and enter


As usual, we can use any other vim positioner to define the "copy to clipboard" area. Ex:

"+yG    (to save from current position to EOF)

This way the text is copied to the system clipboad and can be paste with the clipbord tecnology, or in a different vim


Vim + X11 Clipboards + ssh

When remote hosts are involved, you need to use ssh -XY remoteHost to enable X11 forwarding. This way:

ssh -XY remoteHost
vim file   # and   "+yG  or  visual selection and "+g

saves text in the clipboard, and it can be paste in the usual ways.

Vim + ssh

If nothing else works we can always:

vim scp://host/file

to edit remote files in local machine...

  • @Zen, my previous answer had some incorrect details. I edited it to include some relevant information about cut&paste to remote hosts. – JJoao Mar 5 '15 at 12:17
  1. Move cursor the beginning of what you want to copy.
  2. Press v
  3. Move cursor to end of what you want to copy by scrolling
  4. Press y

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.