Last active
August 29, 2015 14:21
-
-
Save AdnoC/88707d795018244bbf32 to your computer and use it in GitHub Desktop.
Make sure you always have vim-plug automatically installed. Always.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" gVim looks for plugins in vimfiles instead of .vim in Windows | |
if has('gui_win32') | |
let s:vimDirectory=expand("$HOME/vimfiles") | |
else | |
let s:vimDirectory=expand("$HOME/.vim") | |
endif | |
" Download the manager if it isn't yet. | |
if empty(glob(expand(s:vimDirectory . '/autoload/plug.vim'))) | |
" I know that all these could be replaced with just the git one. I don't care. | |
if executable("curl") | |
silent exec '!curl -fLo ' . shellescape(expand(s:vimDirectory."/autoload/plug.vim")) . | |
\ ' --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' | |
elseif executable("wget") | |
" wget can't make folders on its own, so we need to make .vim/autoload for it | |
if executable("mkdir") | |
silent exec '!mkdir -p ' . shellescape(expand(s:vimDirectory."/autoload/")) | |
endif | |
silent exec '!wget -q -O ' . shellescape(expand(s:vimDirectory."/autoload/plug.vim")) . | |
\ ' https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' | |
" If we are on Windows we can use Powershell to download it | |
elseif executable("powershell") | |
silent exec '!if not exist ' . shellescape(expand(s:vimDirectory)) . ' mkdir ' . | |
\ shellescape(expand(s:vimDirectory."/autoload/")) | |
silent exec '!powershell "(new-object System.Net.WebClient).DownloadFile(''https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'',''' . | |
\ shellescape(expand(s:vimDirectory."/autoload/plug.vim")) . ''')"' | |
" If all else fails we can just use git. | |
elseif executable("git") | |
silent exec '!git clone -q --depth=1 git@github.com:junegunn/vim-plug.git ' . | |
\ shellescape(expand(s:vimDirectory."/temp")) | |
" Use the correct commands to move/delete files/folders | |
if has('gui_win32') | |
let s:mv="move " | |
let s:rm="del " | |
else | |
let s:mv="mv " | |
let s:rm="rm -rf " | |
endif | |
silent exec '!' . s:mv . shellescape(expand(s:vimDirectory."/temp/plug.vim")) . | |
\ ' ' . shellescape(expand(s:vimDirectory."/autoload/plug.vim")) | |
silent exec '!' . s:rm . shellescape(expand(s:vimDirectory."/temp/")) | |
else | |
echo "Couldn't find a way to download Vim-Plug. Not sure how you were planning on installing" . | |
\ " plugins without Git." | |
endif | |
" Install the plugins once you enter Vim | |
autocmd VimEnter * PlugInstall | |
endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment