I want to yank text with a command to vim and have it end up in screen's clipboard where it can be pasted to a different application via ^A] later. vim needs to do the copying (not screen's copy mode) because I have more text than will fit on screen at one time.

Answers to other questions have approached this issue, but they mostly rely on using vim's interfaces + and * to the X clipboard, which is not available to applications started remotely or not in the presence of an X session to begin with. I'm working through puTTY, but that's incidental as I just want to transfer between screens and not [necessarily] out to local.

The best thing would be the existence of a magic buffer in vim that connects to screen, but I'll listen to workarounds : )

  • I use Putty (Windows to Linux), for me I can highlight the text in the tty by holding the left mouse button down, then clicking the right mouse button (without lifting the left button). This copies the highlighted section, and I can use the traditional ctl + V, in my local Windows machine. to reverse the process I can ctl + c in windows, then in the tty terminal navigate to the location where I want to paste and just use the right mouse button to paste. Is that what you're looking for?
    – Ben Plont
    Jul 31, 2014 at 22:03
  • @BenPlont The OPs question is very different from what you're describing. They're looking to get vim to copy to [screen](screen)'s copy-paste buffer. What you're describing is copying text from a terminal into your system copy-paste buffer.
    – ernie
    Jul 31, 2014 at 22:30

1 Answer 1


If some extra keystrokes do not bother you, I can‘t see a problem.

GNU Screen’s copy-paste register (.) can be read from / written to file out of a box: <C-a>< and <C-a>> are default hotkeys, /tmp/screen-exchange is a default file, but I’d prefer a user-specific rather than system-wide so I would set something like this in the .screenrc:

setenv BUFFERFILE "$HOME/.buffer" 
bufferfile "$BUFFERFILE"

Vim has no such commands out of a box, but there is no difficulty to create and map them to whatever you want, e. g. <leader>< and <leader>> respectively:

if exists("$BUFFERFILE")
    nnoremap <silent><leader>< :let @" = join(readfile($BUFFERFILE), "\n")<CR>
    nnoremap <silent><leader>> :call writefile( split(@", "\n"), $BUFFERFILE )<CR>

If they do bother you however, it becomes a little more complicated – as far as understood, you have to:

  • remap all possible yank, cut (since there is no autocmd event at changing certain register) and paste (since it’s actually the only feasible trigger) shortcuts in Vim – nothing complex but tedious – I hope, you know how to do it;
  • remap two shortcuts in GNU Screen: while pasting one is quite obvious:

     bind ] eval readbuf "paste ."

    yanking one – <Return> or <Space> in a special copying mode presents a difficulty to me.

  • Perfect seamless integration is not worth the hassle - maybe someday! I saved my text to disk and then loaded screen's buffer from that file, and that works for me. Looks like saving to the exchange file would be one less step on top of that.
    – gws
    Aug 5, 2014 at 16:59
  • im not sure how you achieved this @gws, i tried above settings. Using visual block to select text, i use <C-a>< i get slurped 0 chars into buffer and buffer file stays empty. maybe thats the read from an empty file.. when i use <C-a>> i get copy buffer written to user/.bufffer. but file remains empty. Now, how do i paste? Is that <C-a>]? Im not getting the full text, or do i need to cat the file? Im not sure all visual block text is copying in. (I have a split screen, so this is why i need this, e.g. when i mouse copy it copies both screens) Nov 7, 2019 at 1:07
  • ok trying a few more times, the .buffer is getting text, just not the entire visual block i have selected. So not sure how to get all the text. I think pasting from buffer is <C-a>] it seems. How do i get the entire block to the buffer? Nov 7, 2019 at 1:13

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.