I wanted to set the VIMHOME variable this way (common to Windows and Linux),
let $VIMHOME=expand("%:p")."/..",
so that VIMHOME is "~/.vim" in Linux or "path/to/vimfiles" in Windows.
I put this in a var.vim file and placed this in the plugin directory. It loads properly, but VIMHOME is set only to "./..".
How do I get the full path of a file using expand?
Is there an easy way to set VIMHOME?
Edit: I changed the expression to:
let $VIMHOME=expand(":p:h")
Now, VIMHOME is set to "~/.vim/plugin" in Linux.
My requirement is setting VIMHOME to "~/.vim" or "path/to/vimfiles". But,
let $VIMHOME=expand(":p:h")
let $VIMHOME=expand("$VIMHOME:p:h")
is not working.
How can I resolve this?
Answer
Put this in your var.vim plugin file:
let $VIMHOME=expand(':p:h:h')
% in expand will refer to the file being edited (i.e. the pathname given on the command line). 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).
No comments:
Post a Comment