2010-06-05 63 views
2

我有几个机器上的DropBox文件夹中存储gVim和便携式python。 DropBox文件夹的位置在每台计算机上都不相同。但是,我希望能够设置.vimrc,以便它自动引用正确的python文件夹,而不管它在哪个计算机上。有没有办法在.vimrc中的变量上使用子字符串函数?

例如,我有gVim在C:\ DropBox \ gVimPortable。

在我的.vimrc,我有以下几点:

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 

有没有办法做到像下面这样?

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 

基本上,我不想硬编码我的python运行时存在的文件夹。它将始终与gVim应用程序在相同的位置。

+0

在回答这个问题(但不是问题),我可能会使用平台特定的VIMINIT。 http://vimdoc.sourceforge.net/htmldoc/starting.html#VIMINIT – msw 2010-06-05 03:07:36

回答

2

我能够使用strpart和strlen函数来做我所需要的。

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 

上面的脚本会自动将python添加到相对于可执行的gVIM的PATH环境变量中。

相关问题