created 2005 · complexity basic · author Tony Mechelynck · version 5.7
It is possible to install several different releases of Vim (for instance, Vim 6.3 "stable" and Vim 7.0 "alpha") on a single computer and decide at run-time which one to use. The present tip tells how. However, it does not solve all of the problems; in particular, it tells how to use either one or the other but not both by the same user at the same time. (It is possible to use both at the same time if "users" are different, or if the matchit plugin is not used.)
1. One version should be chosen as "default", normally the more stable one. It will be accessible via the PATH, through one of the following methods:
a. Put the name of its directory in the PATH: for example, on Windows 98, AUTOEXEC.BAT may contain:
... set VIM=C:\PROGRA~1\vim ... path %VIM%\vim63;%PATH%
b. Have a soft link to it in a directory in the PATH, for example on Unix you may have a soft link
/usr/bin/vim pointing to
To use the non-default version (or, on Windows, the default when you are in the directory of the other one), use a full path. In the case above, you will invoke the default Vim as "vim" and the other one as (for example, on Windows) %VIM%\vim70aa\vim
2. The permanent environment may possibly contain a VIM variable (which may for instance be set to
C:\PROGRA~1\vim on Windows or to
/usr/share/vim on Unix) but not a VIMRUNTIME variable. Each executable will select a different $VIMRUNTIME according to its version number. If VIM is unset, Vim will normally set it correctly; but even if you use the default it can be useful to set VIM in the permanent environment so that the shell can see it: indeed, it is much easier to type cd $VIM than cd /usr/share/vim; or %VIM%\vim70aa\gvim filename.ext than "C:\Program Files\vim\vim70aa\gvim" filename.ext. For best results on Windows, use "short" directory names in the value of VIM, HOME, etc. (as in the W98 example above).
3. The "system-wide customizations" in $VIM/vimfiles and the "user-specific customizations" in $HOME/.vim or $HOME/vimfiles will be common to the different versions; any differences can be resolved by testing the value of v:version at run-time.
4. Each distribution should have its own distribution tree at the proper place under $VIM, for instance $VIM/vim63 for stable release 6.3 (at any patchlevel) or $VIM/vim70aa for alpha release 7.0aa (at any snapshot date). If you install via a pre-compiled archive or installer, it should select the proper default. If you compile your own, the subdirectory name is the value of the constant VIM_VERSION_NODOT defined in src/version.h
5. Now we come to the ticklish point: the matchit plugin. It comes with each distribution, with its own script and helpfile, but they are deactivated by default and they may vary from version to version. They are however, very useful; but how can we sure of using the right one? Here is how I solve the dilemma: I use a small "system-wide" plugin $VIM/matchit.vim to automatically select the right plugin at run-time (the first line takes care of the plugin itself; the rest is for the help file. This "fancy footwork" is needed to avoid changing the distribution files in or under $VIMRUNTIME.) Note that the following assumes that different users may use both versions at the same time, but that a single user will not. The contents of that scriptlet is shown here; it assumes that +eval (expression evaluation) and +windows (the ability to use split windows) have been compiled-in. In other words, the "normal" feature set should be enough. (With only "small" features, we can't use the :if statement and that's a big handicap.) This plugin also assumes that there exists a "doc" subdirectory in ~/vimfiles or ~/.vim for "user help files". You should create that directory if it doesn't yet exist.
runtime! macros/matchit.vim split $VIMRUNTIME/macros/matchit.txt if has("unix") saveas! ~/.vim/doc/matchit.txt helptags ~/.vim/doc else saveas! ~/vimfiles/doc/matchit.txt helptags ~/vimfiles/doc endif close
References[edit | edit source]
Similar tip[edit | edit source]
- The philosophy is different: the present tip applies to any OS: it relies on naming one version the "default" and having it in the PATH; other versions must be invoked with an explicit path. The tip named above is only for recent versions of Windows, naming an alternative to Unix's long-established soft links, and tells you how to change the default between a number of installed versions.
Comments[edit | edit source]
Actually, the current matchit plugin and help for 6.3 and 7.0aa are identical, so if that's the ones you have, there is no need for "fancy footwork" to get the right helpfile. Just source the macros/matchit.vim plugin and leave the help files alone.
Anyway, I find that I can live with "not changing the help files" even if it means that I'll occasionally be running with a matchit help for a different (later?) version of matchit than the one I'm currently using (when using a version of Vim other than my "default Vim"). -- Tonymec 05:30, 6 January 2008 (UTC)