1 " ---------------------------------------------------------------------------
3 " ---------------------------------------------------------------------------
5 set nocompatible " essential
6 set history=1000 " lots of command line history
7 set confirm " error files / jumping
8 set fileformats=unix,dos,mac " support these files
9 set iskeyword+=_,$,@,%,#,- " none word dividers
10 set viminfo='1000,f1,:100,@100,/20
11 set modeline " make sure modeline support is enabled
12 set autoread " reload files (no local changes only)
14 " ---------------------------------------------------------------------------
16 " ---------------------------------------------------------------------------
18 call plug#begin('~/.vim/plugged')
21 Plug 'tonyduckles/vim-colorschemes'
24 Plug 'airblade/vim-gitgutter' " shows git diff in the gutter
25 Plug 'farmergreg/vim-lastplace' " intelligently reopen files at your last edit position
26 Plug 'godlygeek/csapprox' " make gui-only colorschemes work automagically in terminal vim
27 Plug 'junegunn/goyo.vim' " distraction-free writing
28 Plug 'junegunn/limelight.vim' " hyperfocus-writing
29 Plug 'kien/ctrlp.vim' " fuzzy file, buffer, mru, etc finder
30 Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' } " file system explorer
31 Plug 'sjl/gundo.vim' " visualize undo tree
32 Plug 'vim-airline/vim-airline' " lean & mean status/tabline
33 Plug 'vim-airline/vim-airline-themes' " themes for vim-airline
36 Plug 'ludovicchabant/vim-gutentags' " automatic ctags
37 Plug 'mileszs/ack.vim' " Ack wrapper
38 Plug 'tpope/vim-fugitive' " Git wrappers
41 Plug 'tpope/vim-surround' " quoting/parenthesizing made simple
42 Plug 'tpope/vim-unimpaired' " pairs of handy bracket mappings
45 Plug 'tpope/vim-git' " filetype=gitcommit
46 Plug 'vim-pandoc/vim-pandoc'
47 Plug 'vim-pandoc/vim-pandoc-syntax' " filetype=markdown
48 Plug '~/.vim/bundle/mumps' " filetype=mumps
49 Plug 'pearofducks/ansible-vim' " filetype=yaml.ansible
52 Plug 'kopischke/vim-fetch' " handle opening filenames with line+column numbers
53 Plug 'tpope/vim-scriptease' " misc collection of helper commands
54 Plug '~/.vim/bundle/airlinetheme-map' " override AirlineTheme for certain colorscheme's
55 Plug '~/.vim/bundle/autofolds' " folds for my *rc files
60 if empty(glob('~/.vim/plugged'))
61 autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
64 " ----------------------------------------------------------------------------
66 " ----------------------------------------------------------------------------
69 let NERDTreeShowHidden=1 " show dotfiles by default
70 let NERDTreeMinimalUI=1 " disable 'Press ? for help' text
74 let g:ctrlp_show_hidden = 1
75 let g:ctrlp_cache_dir = $HOME.'/.vim/.cache/ctrlp'
76 let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files . -co --exclude-standard', 'find %s -type f']
79 let g:airline_mode_map = {
92 if !exists('g:airline_symbols')
93 let g:airline_symbols = {}
96 let g:airline_powerline_fonts = 1 " use powerline font symbols
98 let g:airline_symbols_ascii = 1 " use plain ascii symbols
99 let g:airline_symbols.branch = ''
101 let g:airline_symbols.colnr = ' '
102 let g:airline_symbols.dirty = '*'
103 let g:airline_symbols.linenr = ' '
104 let g:airline_symbols.maxlinenr = ''
105 let g:airline_symbols.notexists = '?'
108 let g:gitgutter_enabled = 0 " disable by default
111 let g:goyo_width = 80
112 let g:limelight_conceal_ctermfg = 240
113 let g:limelight_default_coefficient = 0.6
114 let g:limelight_paragraph_span = 1 " show adjacent paragraphs
115 let g:limelight_priority = -1 " don't overrule hlsearch
117 function! s:goyo_enter()
119 silent !tmux list-panes -F '\#F' | grep -q Z || tmux resize-pane -Z
125 function! s:goyo_leave()
127 silent !tmux list-panes -F '\#F' | grep -q Z && tmux resize-pane -Z
133 autocmd! User GoyoEnter nested call <SID>goyo_enter()
134 autocmd! User GoyoLeave nested call <SID>goyo_leave()
137 let g:pandoc#syntax#conceal#use = 0 " disable conceal pretty display
138 let g:pandoc#folding#fdc = 0 " disable foldcolumn
139 let g:pandoc#folding#level = 6 " open all folds by default
142 let g:gutentags_enabled_user_func = 'GutentagsCheckEnabled'
143 function! GutentagsCheckEnabled(file)
144 let file_path = fnamemodify(a:file, ':p:h')
146 " enable gutentags if ctags file already exists
147 " tip: `touch tags` in project root to enable gutentags auto-updating
149 let gutentags_root = gutentags#get_project_root(file_path)
150 if filereadable(gutentags_root . '/tags')
159 " ---------------------------------------------------------------------------
161 " ---------------------------------------------------------------------------
163 if !has("gui_running") && !(&term =~ '256color')
164 if has("terminfo") && ! (&term == 'linux' || &term == 'Eterm' || &term == 'vt220' || &term == 'nsterm-16color' || &term == 'xterm-16color')
165 " Force these terminals to accept my authority! (default)
167 set t_AB=
\e[%?%p1%{8}%<%t%p1%{40}%+%e%p1%{92}%+%;%dm " ANSI background
168 set t_AF=
\e[%?%p1%{8}%<%t%p1%{30}%+%e%p1%{82}%+%;%dm " ANSI foreground
169 elseif &term == 'term' || &term == 'rxvt' || &term == 'vt100' || &term == 'screen'
170 " Less-Cool Terminals (no terminfo)
172 set t_AB=
\e[%?%p1%{8}%<%t4%p1%d%e%p1%{32}%+%d;1%;m
173 set t_AF=
\e[%?%p1%{8}%<%t3%p1%d%e%p1%{22}%+%d;1%;m
175 " Terminals that have trustworthy terminfo entries
178 set t_Sf=
\e[3%dm " foreground
179 set t_Sb=
\e[4%dm " background
180 elseif $TERM == 'xterm'
186 " ---------------------------------------------------------------------------
188 " ---------------------------------------------------------------------------
190 if &t_Co > 2 || has("gui_running")
191 set background=dark " dark background
192 syntax enable " syntax highligting
194 " override colors in solarized colorscheme
195 augroup vimrc_colorscheme_solarized
197 if !has("gui_running")
198 " override Normal ctermfg
199 autocmd ColorScheme solarized highlight Normal ctermfg=None
200 " override Comment ctermfg
202 autocmd ColorScheme solarized highlight Comment ctermfg=241
204 autocmd ColorScheme solarized highlight Comment ctermfg=DarkGrey
206 " override visual block
207 autocmd ColorScheme solarized highlight Visual term=reverse cterm=reverse ctermfg=DarkGreen ctermbg=White
209 " override unprintable chars (listchars)
210 autocmd ColorScheme solarized highlight SpecialKey ctermfg=DarkGrey ctermbg=Black
215 " colorscheme theme options
216 let g:solarized_termcolors=&t_Co " use 256 colors for solarized
217 let g:solarized_termtrans=1
219 if !exists('s:set_colorscheme')
220 colorscheme solarized
221 let s:set_colorscheme=1
224 " airline theme options
225 let g:solarized16_termcolors=16 " always use 16 colors for 'solarized16' vim-airline theme
226 let g:colorscheme_airlinetheme_map = {
227 \ 'seoul256-light': 'zenburn',
228 \ 'solarized': 'solarized16',
230 let g:colorscheme_airlinetheme_default = 'distinguished'
234 " ----------------------------------------------------------------------------
236 " ----------------------------------------------------------------------------
238 set nobackup " do not keep backups after close
239 set nowritebackup " do not keep a backup while working
240 set backupcopy=yes " keep attributes of original file
241 set backupskip=/tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*
242 set directory=.,~/tmp,~/.vim/swap " swap file directory-order
243 set updatetime=1000 " idle time before writing swap file to disk
245 " ----------------------------------------------------------------------------
247 " ----------------------------------------------------------------------------
249 set ruler " show the cursor position all the time
250 set showcmd " display incomplete commands
251 set nolazyredraw " turn off lazy redraw
252 set hidden " keep buffers loaded when hidden
253 set showmode " show mode at bottom of screen
254 set wildmenu " turn on wild menu
255 set wildmode=list:longest,full
256 set cmdheight=2 " command line height
257 set backspace=2 " allow backspacing over everything in insert mode
258 set whichwrap+=<,>,h,l,[,] " backspace and cursor keys wrap to
259 set shortmess=filtIoO " shorten messages
260 set report=0 " tell us about changes
261 set nostartofline " don't jump to the start of line when scrolling
262 set scrolloff=4 " vertical padding
263 set sidescroll=40 " side-scrolling increment (for nowrap mode)
264 set sidescrolloff=10 " horz padding
265 set tabpagemax=15 " open 15 tabs max
266 set splitright " put new vsplit windows to the right of the current
268 " ----------------------------------------------------------------------------
270 " ----------------------------------------------------------------------------
272 set showmatch " brackets/braces that is
273 set matchtime=5 " duration to show matching brace (1/10 sec)
274 set incsearch " do incremental searching
275 set laststatus=2 " always show the status line
276 set ignorecase " ignore case when searching
277 set smartcase " case-sensitive if search contains an uppercase character
278 set visualbell " shut the heck up
279 set hlsearch " highlight all search matches
280 set list listchars=trail:·,tab:▸\ ,precedes:<,extends:> " show trailing whitespace and tab chars
282 " ----------------------------------------------------------------------------
284 " ----------------------------------------------------------------------------
286 if !exists(':AirlineTheme')
287 set statusline=%1*\ %n%0*\ %<%f " buffer #, filename
288 set statusline+=\ %h%m%r " file-state flags
289 set statusline+=%= " left-right divider
290 set statusline+=%{strlen(&fenc)?&fenc:&enc},%{&ff}\ %y " file-encoding, format, type
291 set statusline+=\ %12.(%v,%l/%L%)\ \ %-4P " cursor position, % through file of viewport
294 " ----------------------------------------------------------------------------
296 " ----------------------------------------------------------------------------
298 set autoindent " automatic indent new lines
299 set smartindent " be smart about it
300 set nowrap " do not wrap lines
301 set softtabstop=2 " yep, two
302 set shiftwidth=2 " ..
304 set expandtab " expand tabs to spaces
305 set smarttab " smarter softtab handling
306 set formatoptions+=n " support for numbered/bullet lists
307 set textwidth=0 " no line-wrapping by default
308 set virtualedit=block " allow virtual edit in visual block ..
309 set spelllang=en_us " spell-check dictionary
311 " ----------------------------------------------------------------------------
312 " Filename Exclusions
313 " ----------------------------------------------------------------------------
315 set wildignore+=.hg,.git,.svn " version control directories
316 set wildignore+=*.jpg,*.jpeg,*.bmp,*.gif,*.png " image files
317 set wildignore+=*.o,*.obj,*.exe,*.dll " compiled object files
318 set wildignore+=*.pyc " Python byte code
319 set wildignore+=*.sw? " Vim swap files
320 set wildignore+=.DS_Store " OSX junk
322 " ----------------------------------------------------------------------------
324 " ----------------------------------------------------------------------------
326 " movement based on display lines not physical lines (sane movement with wrap turned on)
335 inoremap <Down> <C-o>gj
336 inoremap <Up> <C-o>gk
337 " do not menu with left / right in command line
338 cnoremap <Left> <Space><BS><Left>
339 cnoremap <Right> <Space><BS><Right>
341 " reflow paragraph with Q in normal and visual mode
344 " remap U to <C-r> for easier redo
346 " make Y consistent with C (c$) and D (d$)
348 " disable default vim regex handling for searching
351 " reselect visual block after indent/outdent
355 " <Space> to turn off highlighting and clear any message already displayed.
356 nnoremap <silent> <Space> :nohlsearch<Bar>:echo<CR>
358 " leader-based keyboard shortcuts
361 nmap <leader>b :CtrlPBuffer<CR>
362 nmap <leader>o :CtrlP<CR>
363 nmap <leader>O :CtrlPClearCache<CR>:CtrlP<CR>
365 nmap <leader>d :NERDTreeToggle<CR>
366 nmap <leader>f :NERDTreeFind<CR>
368 nmap <leader>u :GundoToggle<CR>
370 nmap <leader>gb :Gblame<CR>
371 nmap <leader>gs :Gstatus<CR>
372 nmap <leader>gd :Gdiff<CR>
373 nmap <leader>gl :Glog<CR>
374 nmap <leader>gc :Gcommit<CR>
375 nmap <leader>gp :Gpush<CR>
376 " cd to the directory containing the file in the buffer
377 nmap <leader>cd :lcd %:h<CR>
378 " toggle quickfix window
379 function! QuickfixToggle()
380 let wcnt_old = winnr("$")
382 let wcnt_cur = winnr("$")
383 if wcnt_old == wcnt_cur
387 nmap <leader>q :call QuickfixToggle()<CR>
388 " toggle diffmode for a buffer
389 function! DiffToggle()
396 nmap <leader>df :call DiffToggle()<CR>
397 " quickly edit/reload vimrc
398 nmap <leader>ev :edit $MYVIMRC<CR>
399 nmap <leader>sv :source $MYVIMRC<CR>
400 " find merge conflict markers
401 nmap <leader>fc <ESC>/\v^[<=>]{7}( .*\|$)<CR>
403 nnoremap <leader>h1 m`yypVr=``
404 nnoremap <leader>h2 m`yypVr-``
405 nnoremap <leader>h3 m`^i### <esc>``4l
406 nnoremap <leader>h4 m`^i#### <esc>``5l
407 nnoremap <leader>h5 m`^i##### <esc>``6l
409 nmap <leader>hls :set hlsearch! hlsearch?<CR>
411 nmap <leader>wu mQviwU`Q
412 nmap <leader>wl mQviwu`Q
413 " upper/lower first char of word
414 nmap <leader>wU mQgewvU`Q
415 nmap <leader>wL mQgewvu`Q
416 " smart paste - enable paste-mode and paste contents of system clipboard
417 map <leader>p :set paste<CR>o<esc>"*]p:set nopaste<cr>
419 nmap <leader>sp :setlocal spell! spell?<CR>
420 " set text wrapping toggles
421 nmap <leader>tw :set wrap! wrap?<CR>
422 " set list-whitespace-chars toggle
423 nmap <leader>ws :set list! list?<CR>
424 " open tag definition in a horz split
425 nmap <leader>tag :split <CR>:exec("tag ".expand("<cword>"))<CR>
427 nmap <leader>ht :GitGutterToggle<CR>
428 nmap <leader>hp <Plug>GitGutterPreviewHunk
429 nmap <leader>hu <Plug>GitGutterUndoHunk
430 nmap <leader>hs <Plug>GitGutterStageHunk
432 nnoremap <leader>G :Goyo<CR>
434 nmap <leader>st :set tabstop=2 softtabstop=2 shiftwidth=2 expandtab<CR>
436 " --------------------------------------------------------------------------
438 " --------------------------------------------------------------------------
441 " Run vim command, redirect output to a scratch buffer
442 function! s:redir(cmd)
450 setlocal buftype=nofile bufhidden=wipe noswapfile nobuflisted nomodified
455 command! -nargs=+ -complete=command Redir call s:redir(<q-args>)
458 " Make a scratch buffer with all of the leader keybindings.
459 command! ListLeaders :call s:redir('nmap <leader>')
462 " Use `git grep` to search for to-do comments, add matches to qflist
463 function! s:todo() abort
465 for cmd in ['git grep -nI -e TODO -e FIXME -e XXX 2> /dev/null',
466 \ 'grep -rnI -e TODO -e FIXME -e XXX * 2> /dev/null']
467 let lines = split(system(cmd), '\n')
468 if v:shell_error != 0 | continue | endif
470 let [fname, lno, text] = matchlist(line, '^\([^:]*\):\([^:]*\):\(.*\)')[1:3]
471 call add(entries, { 'filename': fname, 'lnum': lno, 'text': text })
477 call setqflist(entries)
481 command! Todo call s:todo()
483 " :StripTrailingWhitespace
484 " Strip trailing whitespace
485 function! StripTrailingWhitespace()
486 " preparation: save last search, and cursor position.
492 " clean up: restore previous search history, and cursor position
496 command! StripTrailingWhitespace call StripTrailingWhitespace()
498 " ---------------------------------------------------------------------------
499 " Auto Commands / File Types
500 " ---------------------------------------------------------------------------
502 " override Filetype settings
503 augroup vimrc_filetype
506 au Filetype sh,bash setlocal ts=4 sts=4 sw=4 expandtab
508 " git commit message: enable spell checking
509 au Filetype gitcommit setlocal spell
510 " gitconfig file: use real tabs
511 au Filetype gitconfig setlocal noexpandtab
512 " javascript: don't use cindent
513 au FileType javascript setlocal nocindent
514 " makefiles: use real tabs
515 au FileType make setlocal noexpandtab
517 au FileType vim setlocal foldmethod=expr foldexpr=autofolds#foldexpr(v\:lnum) foldtext=autofolds#foldtext() foldlevel=2
518 au FileType sh setlocal foldmethod=expr foldexpr=autofolds#foldexpr(v\:lnum,'sh') foldtext=autofolds#foldtext() foldlevel=2
519 " pearofducks/ansible-vim
520 au BufRead,BufNewFile */playbooks/*.yml set filetype=yaml.ansible
521 au BufNewFile,BufRead hosts.ini set filetype=yaml.ansible
524 " --------------------------------------------------------------------------
526 " --------------------------------------------------------------------------
528 if filereadable(glob("~/.vimrc.local"))
529 source ~/.vimrc.local