.vimrc 变量不被评估

.vimrc variables are not evaluated

我正在尝试为 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-. 中记录的字符串连接运算符。