up vote 1 down vote favorite
1
share [g+] share [fb]

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("<sfile>: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("<sfile>:p:h")
let $VIMHOME=expand("$VIMHOME:p:h")

is not working.

How can I resolve this?

link|improve this question

Add another :h. I have updated my answer. – Chris Johnsen Mar 15 '10 at 9:30
oh.. Thanx thats working as well.. – asdfg Mar 15 '10 at 9:55
feedback

2 Answers

up vote 3 down vote accepted

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).

link|improve this answer
feedback

This is what I was looking for,

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

I found this here

link|improve this answer
Not always true: some people have vim installed in (and hence $VIM set to) C:\Program Files\Vim and the settings in C:\Documents and Settings\%USERNAME%\vimfiles. A safe way is to have a file installed in vimfiles and use globpath(&rtp, filename). – Al. Mar 15 '10 at 13:44
The accepted answer works properly.. thanx – asdfg Mar 17 '10 at 5:19
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.