Переменные .vimrc не оцениваются - PullRequest
1 голос
/ 20 октября 2019

Я пытаюсь создать сценарий установки для 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

1 Ответ

2 голосов
/ 20 октября 2019

Вы можете использовать execute для оценки переменных в командах. Для вашего случая:

silent execute '!wget -o '.s:destinefile.' --force-directories '.s:downloadurl

Здесь точка - оператор объединения строк, задокументированный в :help expr-..

...