Vim-plug: Tips should also describe automatic installation for Neovim

Created on 4 Mar 2018  路  4Comments  路  Source: junegunn/vim-plug

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

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/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 :)

All 4 comments

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?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fvictorio picture fvictorio  路  3Comments

Mryehua picture Mryehua  路  4Comments

zQueal picture zQueal  路  4Comments

meain picture meain  路  3Comments

bmcilw1 picture bmcilw1  路  3Comments