How can I cause vim to copy text to GNU screen's clipboard buffer?
Solution 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>
endif
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.