动态加载Vim脚本

时间:2013-12-04 18:06:36

标签: vim

在我的dotfiles配置中,我正在尝试构建它,以便我可以自动加载某个文件夹中的* .vim文件。为此,我将以下代码添加到.vimrc文件中:

function PluginConfigs ()
    let vimscripts = split(globpath("$ZSH/vim", '*.vim'), '\n')
    for i in vimscripts
        echom i
        source i
    endfor
endfunction
call PluginConfigs()

当我打开Vim时,我得到以下输出:

/home/davejlong/.dotfiles/vim/dispatch.vim
Error detected while processing function PluginConfigs:
line    4:
E484: Can't open file i
/home/davejlong/.dotfiles/vim/leaders.vim
E484: Can't open file i
/home/davejlong/.dotfiles/vim/matchtagalways.vim
E484: Can't open file i
/home/davejlong/.dotfiles/vim/neocomplete.vim
E484: Can't open file i
Press ENTER or type command to continue

我不确定为什么我不能在i命令中使用变量source

1 个答案:

答案 0 :(得分:0)

当然我在发布问题之后就知道了。我将功能更改为此功能并且有效:

function PluginConfigs ()
    let vimscripts = split(globpath("$ZSH/vim", '*.vim'), '\n')
    for i in vimscripts
        exec ":source " . i
    endfor
endfunction
call PluginConfigs()

您似乎需要使用exec从变量中提取文件。