Skip to content

Instantly share code, notes, and snippets.

@bw-matthew
Last active August 29, 2015 14:22
Show Gist options
  • Save bw-matthew/d52f17294f292135e93f to your computer and use it in GitHub Desktop.
Save bw-matthew/d52f17294f292135e93f to your computer and use it in GitHub Desktop.
Clojure vimrc
" Guard against loading this twice. This does mean you cannot do:
" source $MYVIMRC
" to pick up changes, but that isn't usually what you want anyway (it does not
" clear existing settings that are no longer being set).
if ( exists('g:loaded_vimrc') && g:loaded_vimrc )
finish
endif
let g:loaded_vimrc = 1
function s:Main()
call s:LoadPlugins()
endfunction
function s:LoadPlugins()
if s:CannotLoadPlugins()
return 0
endif
if s:CanInstallPluginLoader() && s:PluginLoaderMissing()
call s:InstallPluginLoader()
endif
call plug#begin('~/.vim/plugged')
call s:RegisterPlugins()
if s:PluginsMissing()
PlugInstall
endif
call plug#helptags()
call plug#end()
call s:ConfigurePlugins()
return 1
endfunction
function s:CannotLoadPlugins()
return version <= 701
endfunction
function s:CanInstallPluginLoader()
" Can only install the plugin loader when vim is starting
return has('vim_starting')
endfunction
function s:PluginLoaderMissing()
return !filereadable(expand('~/.vim/autoload/plug.vim'))
endfunction
function s:InstallPluginLoader()
echo "Installing Vim Plug.."
echo ""
silent !mkdir --parents ~/.vim/autoload
silent !curl --fail --location --output ~/.vim/autoload/plug.vim https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
endfunction
function s:RegisterPlugins()
" Each of these is registered in the g:plugs map.
Plug 'https://github.com/tpope/vim-classpath.git'
Plug 'https://github.com/tpope/vim-dispatch.git'
Plug 'https://github.com/tpope/vim-leiningen.git'
Plug 'https://github.com/kien/rainbow_parentheses.vim.git'
Plug 'https://github.com/tpope/vim-sensible.git'
endfunction
function s:PluginsMissing()
" The g:plugs map maps the plugin name to the settings for it.
" The most relevant setting for this is the 'dir' setting which is the
" destination folder.
" Example (truncated) output of ':echo g:plugs':
" {'vim-surround': {'uri': 'https://github.com/tpope/vim-surround.git', 'dir': '/home/matthew/.vim/plugged/vim-surround/', 'frozen': 0, 'branch': 'master'},...
for spec in values(g:plugs)
if !isdirectory(spec.dir)
return 1
endif
endfor
return 0
endfunction
function s:ConfigurePlugins()
call s:ConfigureColors()
call s:ConfigureRainbowParenthesis()
endfunction
function s:ConfigureColors()
" Convince Vim it can use 256 colors inside Gnome Terminal.
" Needs CSApprox plugin
set t_Co=256
endfunction
function s:ConfigureRainbowParenthesis()
" Load rainbow parens for clojure files
autocmd FileType clojure RainbowParenthesesToggle
autocmd Syntax clojure RainbowParenthesesLoadRound
autocmd Syntax clojure RainbowParenthesesLoadSquare
autocmd Syntax clojure RainbowParenthesesLoadBraces
endfunction
call s:Main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment