From 1b532523c5adf672fcf496ab9f43b41b7e06133e Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Tue, 13 Feb 2018 17:02:08 +1100 Subject: [PATCH] Handle older Vims that don't have native package support by falling back on junegunn/vim-plug --- config/vim/init.vim | 24 +++++---- config/vim/plugins.vim | 118 +++++++++++++++++++++++++---------------- 2 files changed, 88 insertions(+), 54 deletions(-) diff --git a/config/vim/init.vim b/config/vim/init.vim index ce87e48..f9a7b45 100644 --- a/config/vim/init.vim +++ b/config/vim/init.vim @@ -7,15 +7,21 @@ function! s:ensure_dir(dir) endif endfunction -" These are really clever - minpac will actually be loaded on the fly only -" when you need to update or clean your packages, rather than all the time. -command! PackUpdate source $XDG_CONFIG_HOME/vim/plugins.vim | call minpac#update() -command! PackClean source $XDG_CONFIG_HOME/vim/plugins.vim | call minpac#clean() +if exists('+packpath') + " These are really clever - minpac will actually be loaded on the fly only + " when you need to update or clean your packages, rather than all the time. + command! PackUpdate source $XDG_CONFIG_HOME/vim/plugins.vim | call minpac#update() + command! PackClean source $XDG_CONFIG_HOME/vim/plugins.vim | call minpac#clean() -" If the pack directory doesn't exist, we haven't installed any packages yet, -" so let's call PackUpdate. -if !isdirectory($XDG_CACHE_HOME . '/vim/pack') - PackUpdate + " If the pack directory doesn't exist, we haven't installed any packages yet, + " so let's call PackUpdate. + if !isdirectory($XDG_CACHE_HOME . '/vim/pack') + PackUpdate + endif +else + " If we're on a version of Vim that doesn't have packages, we have to load a + " plugin manager (vim-plug) on every boot. + source $XDG_CONFIG_HOME/vim/plugins.vim endif augroup transparent_term @@ -31,7 +37,7 @@ let g:gruvbox_improved_warnings=1 " transparent background colours. It works totally fine in Neovim though. if has('gui_running') || has('nvim') set termguicolors - packadd gruvbox + silent! packadd gruvbox let g:airline_theme = 'gruvbox' colorscheme gruvbox else diff --git a/config/vim/plugins.vim b/config/vim/plugins.vim index c244c9d..2b8e71b 100644 --- a/config/vim/plugins.vim +++ b/config/vim/plugins.vim @@ -1,55 +1,83 @@ -silent! packadd minpac -if !exists('*minpac#init') - silent !git clone https://github.com/k-takata/minpac.git $XDG_CACHE_HOME/vim/pack/minpac/opt/minpac - augroup minpac - autocmd! - autocmd VimEnter * call minpac#update() - augroup END +if exists('+packpath') + silent! packadd minpac + if !exists('*minpac#init') + silent !git clone https://github.com/k-takata/minpac.git $XDG_CACHE_HOME/vim/pack/minpac/opt/minpac + augroup minpac + autocmd! + autocmd VimEnter * call minpac#update() + augroup END + endif + + function! Plug(...) + call call('minpac#add', a:000) + endfunction + + function! PlugEnd() + endfunction + + packadd minpac + + call minpac#init({'dir': $XDG_CACHE_HOME . '/vim'}) +else + if !filereadable($XDG_CACHE_HOME . '/vim/autoload/plug.vim') + silent !curl -fLo $XDG_CACHE_HOME/vim/autoload/plug.vim --create-dirs 'https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' + augroup vimplug + autocmd VimEnter * PlugInstall + augroup END + endif + + function! Plug(name, ...) + call plug#(name) + endfunction + + function! PlugEnd() + call plug#end() + endfunction + + call plug#begin($XDG_CACHE_HOME . '/vim/plugged') endif -packadd minpac +call Plug('k-takata/minpac', {'type': 'opt'}) +call Plug('tpope/vim-sensible') -call minpac#init({'dir': $XDG_CACHE_HOME . '/vim'}) -call minpac#add('k-takata/minpac', {'type': 'opt'}) -call minpac#add('tpope/vim-sensible') +call Plug('ciaranm/inkpot', {'type': 'opt', 'do': 'colorscheme inkpot'}) +call Plug('morhetz/gruvbox', {'type': 'opt'}) -call minpac#add('ciaranm/inkpot', {'type': 'opt', 'do': 'colorscheme inkpot'}) -call minpac#add('morhetz/gruvbox', {'type': 'opt'}) +call Plug('editorconfig/editorconfig-vim') +call Plug('jamessan/vim-gnupg') +call Plug('junegunn/fzf') +call Plug('junegunn/fzf.vim') +call Plug('junegunn/vim-easy-align') +call Plug('lifepillar/vim-mucomplete') +call Plug('mhinz/vim-signify') +call Plug('scrooloose/nerdtree') +call Plug('sjl/vitality.vim') +call Plug('tpope/vim-commentary') +call Plug('tpope/vim-endwise') +call Plug('tpope/vim-fugitive') +call Plug('tpope/vim-repeat') +call Plug('tpope/vim-rhubarb') +call Plug('tpope/vim-sleuth') +call Plug('tpope/vim-surround') +call Plug('tpope/vim-unimpaired') +call Plug('vim-airline/vim-airline') +call Plug('vim-airline/vim-airline-themes') +call Plug('wincent/loupe') +call Plug('wincent/terminus') +call Plug('w0rp/ale') -call minpac#add('editorconfig/editorconfig-vim') -call minpac#add('jamessan/vim-gnupg') -call minpac#add('junegunn/fzf') -call minpac#add('junegunn/fzf.vim') -call minpac#add('junegunn/vim-easy-align') -call minpac#add('lifepillar/vim-mucomplete') -call minpac#add('mhinz/vim-signify') -call minpac#add('scrooloose/nerdtree') -call minpac#add('sjl/vitality.vim') -call minpac#add('tpope/vim-commentary') -call minpac#add('tpope/vim-endwise') -call minpac#add('tpope/vim-fugitive') -call minpac#add('tpope/vim-repeat') -call minpac#add('tpope/vim-rhubarb') -call minpac#add('tpope/vim-sleuth') -call minpac#add('tpope/vim-surround') -call minpac#add('tpope/vim-unimpaired') -call minpac#add('vim-airline/vim-airline') -call minpac#add('vim-airline/vim-airline-themes') -call minpac#add('wincent/loupe') -call minpac#add('wincent/terminus') -call minpac#add('w0rp/ale') +call Plug('LaTeX-Box-Team/LaTeX-Box') +call Plug('vhda/verilog_systemverilog.vim') +call Plug('sheerun/vim-polyglot') +call Plug('sukima/xmledit') -call minpac#add('LaTeX-Box-Team/LaTeX-Box') -call minpac#add('vhda/verilog_systemverilog.vim') -call minpac#add('sheerun/vim-polyglot') -call minpac#add('sukima/xmledit') - -call minpac#add('lepture/vim-jinja') - -call minpac#add('alx741/yesod.vim') -call minpac#add('pbrisbin/vim-syntax-shakespeare') +call Plug('lepture/vim-jinja') +call Plug('alx741/yesod.vim') +call Plug('pbrisbin/vim-syntax-shakespeare') if has('macunix') - call minpac#add('itspriddle/vim-marked') + call Plug('itspriddle/vim-marked') endif + +call PlugEnd()