https://github.com/junegunn/vim-plug/wiki/tips#automatic-installation should also state the code for Neovim:
if empty(glob('~/.local/share/nvim/site/autoload/plug.vim'))
silent !curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
A minor improvement might be to use stdpath() which resolves XDG directories by itself:
" 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
endif
unlet autoload_plug_path
I am trying to setup auto install on neovim on OS X. The first problem with the above code is that neovim seems to look for config in ~/.config/nvim rather than ~/.local/share/nvim, so stdpath('data') should be stdpath('config').
The other problem is that VimEnter event happens after all the startup processing, so any directives in the init.vim that require the plugins will fail (yes, the config will get reloaded, but still, getting all those errors for no reason is... inelegant). What seems cleaner is this
let plug_install = 0
let autoload_plug_path = stdpath('config') . '/autoload/plug.vim'
if !filereadable(autoload_plug_path)
silent exe '!curl -fL --create-dirs -o ' . autoload_plug_path .
\ ' https://raw.github.com/junegunn/vim-plug/master/plug.vim'
execute 'source ' . fnameescape(autoload_plug_path)
let plug_install = 1
endif
unlet autoload_plug_path
call plug#begin('~/.config/nvim/plugins')
... plugins ...
call plug#end()
if plug_install
PlugInstall --sync
endif
unlet plug_install
... the rest of the config goes here ...
This way, I can just download my init.vim into ~/.config/nvim and start nvim and I am all set :)
@MadWombat but the _automatically downloaded_ plug.vim is no configuration, so it makes total sense in the data dir, or not?
Most helpful comment
I am trying to setup auto install on neovim on OS X. The first problem with the above code is that neovim seems to look for config in
~/.config/nvimrather than~/.local/share/nvim, sostdpath('data')should bestdpath('config').The other problem is that VimEnter event happens after all the startup processing, so any directives in the init.vim that require the plugins will fail (yes, the config will get reloaded, but still, getting all those errors for no reason is... inelegant). What seems cleaner is this
This way, I can just download my init.vim into ~/.config/nvim and start nvim and I am all set :)