I'm trying to adapt this known-working snippet for installing vim-plug:

if empty(glob('~/.vim/autoload/plug.vim'))
  silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
    \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
  autocmd VimEnter * PlugInstall | source $MYVIMRC

Seeing as I already have set runtimepath=$XDG_CONFIG_HOME/vim, I tried:

let vimplug=$XDG_CONFIG_HOME."/vim/.vim/autoload/plug.vim" 
if empty(glob(vimplug))
    silent execute '!curl -fLo '.vimplug.' --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
    autocmd VimEnter * PlugInstall | source $MYVIMRC 

Which errors on exit with:

> You don't have permission to create /vim

which suggests to me that it's evaluating $XDG_CONFIG_HOME to an empty string, but it is set, so this is where I'm stuck.

I added the execute because I understood that to be the correct way to evaluate variables before executing a command; what have I missed?

  • What is the output of :echomsg string('!curl -fLo '.vimplug.' --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim') ? Sep 14, 2016 at 18:56
  • Well, clearly the $XDG_CONFIG_HOME is not set. Do you try to set it yourself somewhere?
    – Sevanteri
    Sep 15, 2016 at 7:08

1 Answer 1


At least on neovim, something like this should work. It uses stdpath() in order to handle XDG env variables and filereadable() which is more readable that empty(glob()):

" Bootstrap Plug 
let autoload_plug_path = stdpath('data') . '/site/autoload/plug.vim'
if !filereadable(autoload_plug_path)
  silent execute '!curl -fLo ' . autoload_plug_path . ' --create-dirs
      \ "https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim"'
  autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
unlet autoload_plug_path
  • nit: Shouldn't this be the other way round? Source .vimrc then update the plugins?
    – Igbanam
    May 21, 2023 at 1:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.