我正在尝试为https://github.com/junegunn/vim-plug/wiki/tips创建安装脚本
if empty(glob('~/.vim/autoload/plug.vim'))
let s:downloadurl = "https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim"
let s:destinedirectory = $HOME . "/.vim/autoload/"
let s:destinefile = s:destinedirectory . "plug.vim"
if !isdirectory(s:destinedirectory)
call mkdir(s:destinedirectory, "p")
echo "Created directory: " . s:destinedirectory
endif
if executable("curl")
silent !curl --location --fail --output s:destinefile --create-dirs s:downloadurl
else
silent !wget -o s:destinefile --force-directories s:downloadurl
endif
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
但是vim不评估我的变量,即不运行命令
wget -o /home/user/.vim/plug.vim --force-directories https://raw.githubusercontent...
正在运行:
wget -o s:destinefile --force-directories s:downloadurl
您可以使用execute
评估命令中的变量。对于您的情况:
silent execute '!wget -o '.s:destinefile.' --force-directories '.s:downloadurl
这里点是:help expr-.
中记录的字符串串联运算符。