You may want to take a look at the clipboard
setting (:help 'clipboard'
). What follows is a recommendation from Gary Johnson (source, via web.archive.org).
You may want to set 'clipboard' in your .vimrc so that you don't
have to use -X all the time. In my situation, I use vim on a
machine that I log in to from various other machines, some of which
have $DISPLAY set even though they don't have an X server. Here is
what I have in my .vimrc:
" Prevent vim from trying to connect to the X server when connecting
" from home, which causes a startup delay of about 14 seconds. I
" usually connect from home via screen.
"
"set clipboard=autoselect,exclude:cons\\\|linux\\\|screen
"
" Using $DISPLAY instead of 'term' should be more reliable. It avoids
" the problem of starting vim without first starting screen and allows
" screen to be used locally without losing vim's X features.
"
if $DISPLAY =~ '\(\(cos\|scs\)\d\+nai\d\+\)\|\(spkpc\d\+\)\|\(tc-garyjohn\)'
set clipboard=autoselect,exclude:.*
endif
(Do notice that you'll need to tweak the if $DISPLAY
line to match your own $DISPLAY
variable).