Vim logo vim online Vim Book Ad

basic Tip #334: Loading scripts in .vimrc safely

 tip karma   Rating 33/11, Viewed by 748 

created:   September 30, 2002 9:59      complexity:   basic
author:   [email protected] (Francis)      as of Vim:   6.0

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

 rate this tip  Life Changing Helpful Unfulfilling 

<<Syntax-based folding for c/c++/java | Copy C++ function declaration into implementation file >>

Additional Notes

[email protected], September 30, 2002 17:15
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).
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
SourceForge Logo