views:

50

answers:

1

I have gVim and portable python stored in a DropBox folder on several machines. The location of the DropBox folder is different on each computer. However, I'd like to be able to setup the .vimrc so that it automatically references the correct python folder no matter what computer it's on.

For example, I have gVim in C:\DropBox\gVimPortable.

In my .vimrc, I have the following:

let s:pp = 'C:\DropBox\PortablePython_1.1_py2.5.4'  " netbook  
if (has('win32') || has('win64')) && isdirectory(s:pp) 
    let $PATH .= ';' . s:pp 
endif 

Is there a way to do something like the following?

let s:pp = $VIMRUNTIME.substring(0, regex.match(/gVimPortable/))."\PortablePython_1.1_py2.5.4" 
if (has('win32') || has('win64')) && isdirectory(s:pp) 
    let $PATH .= ';' . s:pp 
endif 

Basically, I don't want to hard code the folder where my python runtime exists. It will always be in the same place relative to the gVim application.

A: 

I was able to do what I needed using the strpart and strlen functions.

let s:pp = strpart($VIMRUNTIME, 0, strlen($VIMRUNTIME)-strridx($VIMRUNTIME, "DropBox")+1) . "\\Apps\\PortablePython_1.1_py2.5.4\\App"
if (has('win32') || has('win64')) && isdirectory(s:pp) 
    let $PATH .= ';' . s:pp 
endif 

The script above will automatically add python to the PATH environment variable relative to the gVIM executeable.

Jim