How do I get Vim home directory?

Put this in your var.vim plugin file:

let $VIMHOME=expand('<sfile>:p:h:h')

% in expand will refer to the file being edited (i.e. the pathname given on the command line). <sfile> will refer to the file being ‘sourced’ (i.e. the plugin or startup file that is active when the expansion is made).

The :p modifier makes the pathname absolute and the :h suffix drops the last pathname component (i.e. the filename in this case).


This is what I was looking for,

if has('win32') || has ('win64')
    let $VIMHOME = $VIM."/vimfiles"
else
    let $VIMHOME = $HOME."/.vim"
endif