I was reading http://vimdoc.sourceforge.net/htmldoc/starting.html#initialization, but couldn't immediately find the answer. Is the $VIM environment variable hardcoded in its binary (not read from a config file)? The binary is built differently depending on the OS, so I'm guessing that's how the $VIM differs per OS.


The whole process can be read under :h $VIM:

To avoid the need for every user to set the $VIM environment variable, Vim will try to get the value for $VIM in this order:

  1. The value defined by the $VIM environment variable. You can use this to make Vim look in a specific directory for its support files. Example: setenv VIM /home/paul/vim
  2. The path from 'helpfile' is used, unless it contains some environment variable too (the default is "$VIMRUNTIME/doc/help.txt": chicken-egg problem). The file name ("help.txt" or any other) is removed. Then trailing directory names are removed, in this order: "doc", "runtime" and
    "vim{version}" (e.g., "vim54").
  3. For MSDOS, Win32 and OS/2 Vim tries to use the directory name of the executable. If it ends in "/src", this is removed. This is useful if you unpacked the .zip file in some directory, and adjusted the search path to find the vim executable. Trailing directory names are removed, in this order: "runtime" and "vim{version}" (e.g., "vim54").
  4. For Unix the compile-time defined installation directory is used (see the output of ":version").

Once Vim has done this once, it will set the $VIM environment variable. To change it later, use a ":let" command like this:

    :let $VIM = "/home/paul/vim/"

Please try to search the helpfile for stuff like that, even tough you could not "immediately find the answer". The vim helpfile is a mighty tool which will guide you a long way before you need this site, once you got the hang of it!


Linux view, for more details see Doktor OSwaldo answer.

The installation directory is defined during build (to be exact: It is defined when configuring the build.). The default value of $VIM is a subdirectory below the installation directory and is compiled in (<inst-dir>/share/vim on Linux).

You can override this by setting the environment variable VIM before starting Vim.

The compiled-in value of $VIM is part of the output from :version or vim --version. Just search for fall-back for $VIM.

Within Vim you can display the actual value by executing

:echo $VIM

Your Answer

