Vim Tips Wiki
Register
Advertisement

Previous TipNext Tip

Tip: #334 - Loading scripts in vimrc safely

Created: September 30, 2002 9:59 Complexity: basic Author: piaip--AT--csie.ntu.edu.tw (Francis) Version: 6.0 Karma: 50/21 Imported from: Tip#334

If you copy your .vimrc to many places, you might get a problem:

writing a portable .vimrc is sometimes painful.

Maybe in some places you have latest VIM6.1, and in some places

you have VIM 5.x. And maybe you have some favorite scripts in

your own computer while other places does not.


Here're some tips and examples on writing portable .vimrc that will not make error

messages when environment changes:


(1) Check version:

if version >= 600

set foldcolumn=2 

endif


(2) Use environment variables:

source $VIMRUNTIME/vimrc_example.vim


(3) Loading scripts(especially useful for scripts just merged into standard macros):

if filereadable($VIMRUNTIME . "/macros/matchit.vim")

source $VIMRUNTIME/macros/matchit.vim 

endif

Comments

Regarding sourcing stuff inside the runtime directory such as the macros stuff, look at the :runtime command -- it doesn't require error checking (though it might be only for 6.x or above so pop it inside the version check).

salmanhalim--AT--hotmail.com , September 30, 2002 17:15


Advertisement