vim -X flag as .vimrc entry
Asked Answered
L

2

6

Is there a config entry I can place in my .vimrc which will achieve the same as passing the -X flag when running vim.

To provide some context: I recently found that my vim startup time in a screen (tmux) session was extremely long (~6 seconds)

Using the vim --startuptime flag, it is clear that the issue is due to the connection to the X server in order to setup the X clipboard.

Running vim -X has fixed my slow startup time. I would prefer to modify my .vimrc, rather than creating a bash alias to solve this.

Louettalough answered 23/5, 2012 at 10:59 Comment(0)
B
7

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).

Bornstein answered 23/5, 2012 at 11:11 Comment(2)
For cygwin: set clipboard=autoselect,exclude:cons\\\|linux\\\|screen\\\|rxvt\\\|cygwin. Thanks!Peterman
Source link is dead.Hedjaz
K
3

Just add to your ~/.vimrc

set clipboard=exclude:.*

Do this mainly to you root user. Other users should work fine connecting the $DISPLAY and clipboard.

Kirtley answered 6/9, 2015 at 4:53 Comment(1)
This will stop the No protocol specified error when running a GUI enabled instance of vim under root.Kirtley

© 2022 - 2024 — McMap. All rights reserved.