Vim Tips Wiki
Register
Advertisement

If you use Vim on both native Windows and Cygwin, or on several virtual machines, you have a couple of options to keep one copy of your vimrc file around, and share that copy among your systems and environments.

Note: For systems that use different line endings, you might need to use Unix line endings everywhere (which don't give problems in Vim for Windows). You can do so via EditorConfig (recommended) or by manually setting 'fileformat'.

The following assumes that you put your vimrc file and all its dependencies in a common directory (preferably under version control).

Option 1: using :source[]

By using the :source command, you can source your "real" vimrc (see above) from each system-specific vimrc. If your real vimrc is large, you can in fact have one "main" Vim script which in turn sources all the others as needed. Then, the system-specific vimrc's will just source the main script. (I recommend this kind of modularization even if you use option 2, below.)

For instance, the vimrc file in your Windows home will look something like:

source X:/path/to/common/dot-files/vim/my_vim.vim

Option 2: using symbolic links[]

Once you have the common files available somewhere, you can make each .vimrc that you need a symbolic link to the common .vimrc "main" file (see above). Under Unix and Cygwin:

$ ln -s /path/to/common/dot-files/vim/my_vim.vim .vimrc


This option, though, is only adequate if your vimrc is very simple. For instance, if it doesn't, in turn, source other files; because, in that case, Vim might have troubles locating those sourced files.

Do not forget that you can use has() and exists() to cope with the different capabilities offered by the various Vim builds and distributions.

Comments[]

Advertisement