]> Tony Duckles's Git Repositories (git.nynim.org) - dotfiles.git/blob - .vimrc
bin/ack: ack v3.4.0
[dotfiles.git] / .vimrc
1 " ---------------------------------------------------------------------------
2 " General
3 " ---------------------------------------------------------------------------
4
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)
13
14 " ---------------------------------------------------------------------------
15 " Plugins
16 " ---------------------------------------------------------------------------
17
18 call plug#begin('~/.vim/plugged')
19
20 " Colors
21 Plug 'ajmwagar/vim-deus'
22 Plug 'AlessandroYorba/Despacio'
23 Plug 'altercation/vim-colors-solarized'
24 Plug 'jacoborus/tender.vim'
25 Plug 'jnurmine/Zenburn'
26 Plug 'junegunn/seoul256.vim'
27 Plug 'Lokaltog/vim-distinguished'
28 Plug 'mhartington/oceanic-next'
29 Plug 'morhetz/gruvbox'
30 Plug 'rakr/vim-two-firewatch'
31 Plug 'vim-scripts/rdark-terminal2.vim'
32 Plug 'vim-scripts/twilight256.vim'
33 Plug 'yorickpeterse/happy_hacking.vim'
34 Plug 'yuttie/hydrangea-vim'
35 Plug 'zacanger/angr.vim'
36
37 " Interface
38 Plug 'airblade/vim-gitgutter' " shows git diff in the gutter
39 Plug 'farmergreg/vim-lastplace' " intelligently reopen files at your last edit position
40 Plug 'godlygeek/csapprox' " make gui-only colorschemes work automagically in terminal vim
41 Plug 'junegunn/goyo.vim' " distraction-free writing
42 Plug 'junegunn/limelight.vim' " hyperfocus-writing
43 Plug 'kien/ctrlp.vim' " fuzzy file, buffer, mru, etc finder
44 Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' } " file system explorer
45 Plug 'sjl/gundo.vim' " visualize undo tree
46 Plug 'vim-airline/vim-airline' " lean & mean status/tabline
47 Plug 'vim-airline/vim-airline-themes' " themes for vim-airline
48
49 " Integrations
50 Plug 'ludovicchabant/vim-gutentags' " automatic ctags
51 Plug 'mileszs/ack.vim' " Ack wrapper
52 Plug 'tpope/vim-fugitive' " Git wrappers
53
54 " Edit
55 Plug 'tpope/vim-surround' " quoting/parenthesizing made simple
56 Plug 'tpope/vim-unimpaired' " pairs of handy bracket mappings
57
58 " Language / Syntax
59 Plug 'tpope/vim-git' " filetype=gitcommit
60 Plug 'vim-pandoc/vim-pandoc'
61 Plug 'vim-pandoc/vim-pandoc-syntax' " filetype=markdown
62 Plug '~/.vim/bundle/mumps' " filetype=mumps
63
64 " Other
65 Plug 'kopischke/vim-fetch' " handle opening filenames with line+column numbers
66 Plug 'tpope/vim-scriptease' " misc collection of helper commands
67 Plug '~/.vim/bundle/airlinetheme-map' " override AirlineTheme for certain colorscheme's
68 Plug '~/.vim/bundle/autofolds' " folds for my *rc files
69
70 call plug#end()
71
72 " Automatic install
73 if empty(glob('~/.vim/plugged'))
74 autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
75 endif
76
77 " ----------------------------------------------------------------------------
78 " Plugin Settings
79 " ----------------------------------------------------------------------------
80
81 " NERDTree
82 let NERDTreeShowHidden=1 " show dotfiles by default
83 let NERDTreeMinimalUI=1 " disable 'Press ? for help' text
84
85 " Ctrl-P
86 let g:ctrlp_map = ''
87 let g:ctrlp_show_hidden = 1
88 let g:ctrlp_cache_dir = $HOME.'/.vim/.cache/ctrlp'
89 let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files . -co --exclude-standard', 'find %s -type f']
90
91 " Airline
92 let g:airline_mode_map = {
93 \ '__' : '-',
94 \ 'n' : 'N',
95 \ 'i' : 'I',
96 \ 'R' : 'R',
97 \ 'c' : 'C',
98 \ 'v' : 'V',
99 \ 'V' : 'V',
100 \ '\16' : 'V',
101 \ 's' : 'S',
102 \ 'S' : 'S',
103 \ '\13' : 'S',
104 \ }
105 if !exists('g:airline_symbols')
106 let g:airline_symbols = {}
107 endif
108 if has("gui_running")
109 let g:airline_powerline_fonts = 1 " use powerline font symbols
110 else
111 let g:airline_symbols_ascii = 1 " use plain ascii symbols
112 let g:airline_symbols.branch = 'BR:'
113 endif
114 let g:airline_symbols.linenr = ''
115 let g:airline_symbols.maxlinenr = ''
116
117 " gitgutter
118 let g:gitgutter_enabled = 0 " disable by default
119
120 " goyo + limelight
121 let g:goyo_width = 80
122 let g:limelight_conceal_ctermfg = 240
123 let g:limelight_default_coefficient = 0.6
124 let g:limelight_paragraph_span = 1 " show adjacent paragraphs
125 let g:limelight_priority = -1 " don't overrule hlsearch
126
127 function! s:goyo_enter()
128 if exists('$TMUX')
129 silent !tmux list-panes -F '\#F' | grep -q Z || tmux resize-pane -Z
130 endif
131 set scrolloff=999
132 Limelight
133 endfunction
134
135 function! s:goyo_leave()
136 if exists('$TMUX')
137 silent !tmux list-panes -F '\#F' | grep -q Z && tmux resize-pane -Z
138 endif
139 set scrolloff=4
140 Limelight!
141 endfunction
142
143 autocmd! User GoyoEnter nested call <SID>goyo_enter()
144 autocmd! User GoyoLeave nested call <SID>goyo_leave()
145
146 " pandoc
147 let g:pandoc#syntax#conceal#use = 0 " disable conceal pretty display
148 let g:pandoc#folding#fdc = 0 " disable foldcolumn
149 let g:pandoc#folding#level = 6 " open all folds by default
150
151 " gutentags
152 let g:gutentags_enabled_user_func = 'GutentagsCheckEnabled'
153 function! GutentagsCheckEnabled(file)
154 let file_path = fnamemodify(a:file, ':p:h')
155
156 " enable gutentags if ctags file already exists
157 " tip: `touch tags` in project root to enable gutentags auto-updating
158 try
159 let gutentags_root = gutentags#get_project_root(file_path)
160 if filereadable(gutentags_root . '/tags')
161 return 1
162 endif
163 catch
164 endtry
165
166 return 0
167 endfunction
168
169 " ---------------------------------------------------------------------------
170 " Terminal Settings
171 " ---------------------------------------------------------------------------
172
173 if !has("gui_running") && !(&term =~ '256color')
174 if has("terminfo") && ! (&term == 'linux' || &term == 'Eterm' || &term == 'vt220' || &term == 'nsterm-16color' || &term == 'xterm-16color')
175 " Force these terminals to accept my authority! (default)
176 set t_Co=16
177 set t_AB=\e[%?%p1%{8}%<%t%p1%{40}%+%e%p1%{92}%+%;%dm " ANSI background
178 set t_AF=\e[%?%p1%{8}%<%t%p1%{30}%+%e%p1%{82}%+%;%dm " ANSI foreground
179 elseif &term == 'term' || &term == 'rxvt' || &term == 'vt100' || &term == 'screen'
180 " Less-Cool Terminals (no terminfo)
181 set t_Co=16
182 set t_AB=\e[%?%p1%{8}%<%t4%p1%d%e%p1%{32}%+%d;1%;m
183 set t_AF=\e[%?%p1%{8}%<%t3%p1%d%e%p1%{22}%+%d;1%;m
184 else
185 " Terminals that have trustworthy terminfo entries
186 if &term == 'vt220'
187 set t_Co=8
188 set t_Sf=\e[3%dm " foreground
189 set t_Sb=\e[4%dm " background
190 elseif $TERM == 'xterm'
191 set term=xterm-color
192 endif
193 endif
194 endif
195
196 " ---------------------------------------------------------------------------
197 " Colors / Theme
198 " ---------------------------------------------------------------------------
199
200 if &t_Co > 2 || has("gui_running")
201 set background=dark " dark background
202 syntax enable " syntax highligting
203
204 " override colors in solarized colorscheme
205 augroup vimrc_colorscheme_solarized
206 autocmd!
207 if !has("gui_running")
208 " override Normal ctermfg
209 autocmd ColorScheme solarized highlight Normal ctermfg=None
210 " override Comment ctermfg
211 if &t_Co == 256
212 autocmd ColorScheme solarized highlight Comment ctermfg=241
213 else
214 autocmd ColorScheme solarized highlight Comment ctermfg=DarkGrey
215 endif
216 " override visual block
217 autocmd ColorScheme solarized highlight Visual term=reverse cterm=reverse ctermfg=DarkGreen ctermbg=White
218 if &t_Co < 256
219 " override unprintable chars (listchars)
220 autocmd ColorScheme solarized highlight SpecialKey ctermfg=DarkGrey ctermbg=Black
221 endif
222 endif
223 augroup END
224
225 " colorscheme theme options
226 let g:solarized_termcolors=&t_Co " use 256 colors for solarized
227 let g:solarized_termtrans=1
228
229 if !exists('s:set_colorscheme')
230 colorscheme solarized
231 let s:set_colorscheme=1
232 endif
233
234 " airline theme options
235 let g:solarized16_termcolors=16 " always use 16 colors for 'solarized16' vim-airline theme
236 let g:colorscheme_airlinetheme_map = {
237 \ 'seoul256-light': 'zenburn',
238 \ 'solarized': 'solarized16',
239 \ }
240 let g:colorscheme_airlinetheme_default = 'distinguished'
241
242 endif
243
244 " ----------------------------------------------------------------------------
245 " Backups
246 " ----------------------------------------------------------------------------
247
248 set nobackup " do not keep backups after close
249 set nowritebackup " do not keep a backup while working
250 set backupcopy=yes " keep attributes of original file
251 set backupskip=/tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*
252 set directory=.,~/tmp,~/.vim/swap " swap file directory-order
253 set updatetime=1000 " idle time before writing swap file to disk
254
255 " ----------------------------------------------------------------------------
256 " UI
257 " ----------------------------------------------------------------------------
258
259 set ruler " show the cursor position all the time
260 set showcmd " display incomplete commands
261 set nolazyredraw " turn off lazy redraw
262 set hidden " keep buffers loaded when hidden
263 set showmode " show mode at bottom of screen
264 set wildmenu " turn on wild menu
265 set wildmode=list:longest,full
266 set cmdheight=2 " command line height
267 set backspace=2 " allow backspacing over everything in insert mode
268 set whichwrap+=<,>,h,l,[,] " backspace and cursor keys wrap to
269 set shortmess=filtIoO " shorten messages
270 set report=0 " tell us about changes
271 set nostartofline " don't jump to the start of line when scrolling
272 set scrolloff=4 " vertical padding
273 set sidescroll=40 " side-scrolling increment (for nowrap mode)
274 set sidescrolloff=10 " horz padding
275 set tabpagemax=15 " open 15 tabs max
276 set splitright " put new vsplit windows to the right of the current
277
278 " ----------------------------------------------------------------------------
279 " Visual Cues
280 " ----------------------------------------------------------------------------
281
282 set showmatch " brackets/braces that is
283 set matchtime=5 " duration to show matching brace (1/10 sec)
284 set incsearch " do incremental searching
285 set laststatus=2 " always show the status line
286 set ignorecase " ignore case when searching
287 set smartcase " case-sensitive if search contains an uppercase character
288 set visualbell " shut the heck up
289 set hlsearch " highlight all search matches
290 set list listchars=trail:·,tab:▸\ ,precedes:<,extends:> " show trailing whitespace and tab chars
291
292 " ----------------------------------------------------------------------------
293 " Status Line
294 " ----------------------------------------------------------------------------
295
296 if !exists(':AirlineTheme')
297 set statusline=%1*\ %n%0*\ %<%f " buffer #, filename
298 set statusline+=\ %h%m%r " file-state flags
299 set statusline+=%= " left-right divider
300 set statusline+=%{strlen(&fenc)?&fenc:&enc},%{&ff}\ %y " file-encoding, format, type
301 set statusline+=\ %12.(%v,%l/%L%)\ \ %-4P " cursor position, % through file of viewport
302 endif
303
304 " ----------------------------------------------------------------------------
305 " Text Formatting
306 " ----------------------------------------------------------------------------
307
308 set autoindent " automatic indent new lines
309 set smartindent " be smart about it
310 set nowrap " do not wrap lines
311 set softtabstop=2 " yep, two
312 set shiftwidth=2 " ..
313 set tabstop=4
314 set expandtab " expand tabs to spaces
315 set smarttab " smarter softtab handling
316 set formatoptions+=n " support for numbered/bullet lists
317 set textwidth=0 " no line-wrapping by default
318 set virtualedit=block " allow virtual edit in visual block ..
319 set spelllang=en_us " spell-check dictionary
320
321 " ----------------------------------------------------------------------------
322 " Filename Exclusions
323 " ----------------------------------------------------------------------------
324
325 set wildignore+=.hg,.git,.svn " version control directories
326 set wildignore+=*.jpg,*.jpeg,*.bmp,*.gif,*.png " image files
327 set wildignore+=*.o,*.obj,*.exe,*.dll " compiled object files
328 set wildignore+=*.pyc " Python byte code
329 set wildignore+=*.sw? " Vim swap files
330 set wildignore+=.DS_Store " OSX junk
331
332 " ----------------------------------------------------------------------------
333 " Key Mappings
334 " ----------------------------------------------------------------------------
335
336 " movement based on display lines not physical lines (sane movement with wrap turned on)
337 nnoremap j gj
338 nnoremap k gk
339 vnoremap j gj
340 vnoremap k gk
341 nnoremap <Down> gj
342 nnoremap <Up> gk
343 vnoremap <Down> gj
344 vnoremap <Up> gk
345 inoremap <Down> <C-o>gj
346 inoremap <Up> <C-o>gk
347 " do not menu with left / right in command line
348 cnoremap <Left> <Space><BS><Left>
349 cnoremap <Right> <Space><BS><Right>
350
351 " reflow paragraph with Q in normal and visual mode
352 nnoremap Q gqap
353 vnoremap Q gq
354 " remap U to <C-r> for easier redo
355 nnoremap U <C-r>
356 " make Y consistent with C (c$) and D (d$)
357 nnoremap Y y$
358 " disable default vim regex handling for searching
359 nnoremap / /\v
360 vnoremap / /\v
361 " reselect visual block after indent/outdent
362 vnoremap < <gv
363 vnoremap > >gv
364
365 " <Space> to turn off highlighting and clear any message already displayed.
366 nnoremap <silent> <Space> :nohlsearch<Bar>:echo<CR>
367
368 " leader-based keyboard shortcuts
369 let mapleader = ","
370 " CtrlP
371 nmap <leader>b :CtrlPBuffer<CR>
372 nmap <leader>o :CtrlP<CR>
373 nmap <leader>O :CtrlPClearCache<CR>:CtrlP<CR>
374 " NERDTree
375 nmap <leader>d :NERDTreeToggle<CR>
376 nmap <leader>f :NERDTreeFind<CR>
377 " Gundo
378 nmap <leader>u :GundoToggle<CR>
379 " Fugitive (Git)
380 nmap <leader>gb :Gblame<CR>
381 nmap <leader>gs :Gstatus<CR>
382 nmap <leader>gd :Gdiff<CR>
383 nmap <leader>gl :Glog<CR>
384 nmap <leader>gc :Gcommit<CR>
385 nmap <leader>gp :Gpush<CR>
386 " cd to the directory containing the file in the buffer
387 nmap <leader>cd :lcd %:h<CR>
388 " toggle quickfix window
389 function! QuickfixToggle()
390 let wcnt_old = winnr("$")
391 cwindow
392 let wcnt_cur = winnr("$")
393 if wcnt_old == wcnt_cur
394 cclose
395 endif
396 endfunction
397 nmap <leader>cc :call QuickfixToggle()<CR>
398 " toggle diffmode for a buffer
399 function! DiffToggle()
400 if &diff
401 diffoff
402 else
403 diffthis
404 endif
405 endfunction
406 nmap <leader>df :call DiffToggle()<CR>
407 " quickly edit/reload vimrc
408 nmap <leader>ev :edit $MYVIMRC<CR>
409 nmap <leader>sv :source $MYVIMRC<CR>
410 " find merge conflict markers
411 nmap <leader>fc <ESC>/\v^[<=>]{7}( .*\|$)<CR>
412 " markdown headings
413 nnoremap <leader>h1 m`yypVr=``
414 nnoremap <leader>h2 m`yypVr-``
415 nnoremap <leader>h3 m`^i### <esc>``4l
416 nnoremap <leader>h4 m`^i#### <esc>``5l
417 nnoremap <leader>h5 m`^i##### <esc>``6l
418 " toggle hlsearch
419 nmap <leader>hls :set hlsearch! hlsearch?<CR>
420 " upper/lower word
421 nmap <leader>wu mQviwU`Q
422 nmap <leader>wl mQviwu`Q
423 " upper/lower first char of word
424 nmap <leader>wU mQgewvU`Q
425 nmap <leader>wL mQgewvu`Q
426 " smart paste - enable paste-mode and paste contents of system clipboard
427 map <leader>p :set paste<CR>o<esc>"*]p:set nopaste<cr>
428 " toggle spell-check
429 nmap <leader>sp :setlocal spell! spell?<CR>
430 " set text wrapping toggles
431 nmap <leader>tw :set wrap! wrap?<CR>
432 " set list-whitespace-chars toggle
433 nmap <leader>ws :set list! list?<CR>
434 " open tag definition in a horz split
435 nmap <leader>tag :split <CR>:exec("tag ".expand("<cword>"))<CR>
436 " gitgutter
437 nmap <leader>ht :GitGutterToggle<CR>
438 nmap <leader>hp <Plug>GitGutterPreviewHunk
439 nmap <leader>hu <Plug>GitGutterUndoHunk
440 nmap <leader>hs <Plug>GitGutterStageHunk
441 " goyo
442 nnoremap <leader>G :Goyo<CR>
443
444 " --------------------------------------------------------------------------
445 " Functions
446 " --------------------------------------------------------------------------
447
448 " :Redir
449 " Run vim command, redirect output to a scratch buffer
450 function! s:redir(cmd)
451 redir => message
452 silent execute a:cmd
453 redir END
454 if empty(message)
455 echoerr "no output"
456 else
457 new
458 setlocal buftype=nofile bufhidden=wipe noswapfile nobuflisted nomodified
459 silent! put=message
460 silent! g/^s*$/d
461 endif
462 endfunction
463 command! -nargs=+ -complete=command Redir call s:redir(<q-args>)
464
465 " :ListLeaders
466 " Make a scratch buffer with all of the leader keybindings.
467 command! ListLeaders :call s:redir('nmap <leader>')
468
469 " :Todo
470 " Use `git grep` to search for to-do comments, add matches to qflist
471 function! s:todo() abort
472 let entries = []
473 for cmd in ['git grep -nI -e TODO -e FIXME -e XXX 2> /dev/null',
474 \ 'grep -rnI -e TODO -e FIXME -e XXX * 2> /dev/null']
475 let lines = split(system(cmd), '\n')
476 if v:shell_error != 0 | continue | endif
477 for line in lines
478 let [fname, lno, text] = matchlist(line, '^\([^:]*\):\([^:]*\):\(.*\)')[1:3]
479 call add(entries, { 'filename': fname, 'lnum': lno, 'text': text })
480 endfor
481 break
482 endfor
483
484 if !empty(entries)
485 call setqflist(entries)
486 copen
487 endif
488 endfunction
489 command! Todo call s:todo()
490
491 " :StripTrailingWhitespace
492 " Strip trailing whitespace
493 function! StripTrailingWhitespace()
494 " preparation: save last search, and cursor position.
495 let _s=@/
496 let l = line(".")
497 let c = col(".")
498 " do the business
499 %s/\s\+$//e
500 " clean up: restore previous search history, and cursor position
501 let @/=_s
502 call cursor(l, c)
503 endfunction
504 command! StripTrailingWhitespace call StripTrailingWhitespace()
505
506 " ---------------------------------------------------------------------------
507 " Auto Commands / File Types
508 " ---------------------------------------------------------------------------
509
510 " override Filetype settings
511 augroup vimrc_filetype
512 autocmd!
513 " sh config
514 au Filetype sh,bash setlocal ts=4 sts=4 sw=4 expandtab
515 let g:is_bash = 1
516 " git commit message: enable spell checking
517 au Filetype gitcommit setlocal spell
518 " gitconfig file: use real tabs
519 au Filetype gitconfig setlocal noexpandtab
520 " javascript: don't use cindent
521 au FileType javascript setlocal nocindent
522 " makefiles: use real tabs
523 au FileType make setlocal noexpandtab
524 " autofolds
525 au FileType vim setlocal foldmethod=expr foldexpr=autofolds#foldexpr(v\:lnum) foldtext=autofolds#foldtext() foldlevel=2
526 au FileType sh setlocal foldmethod=expr foldexpr=autofolds#foldexpr(v\:lnum,'sh') foldtext=autofolds#foldtext() foldlevel=2
527 augroup END
528
529 " --------------------------------------------------------------------------
530 " Local Settings
531 " --------------------------------------------------------------------------
532
533 if filereadable(glob("~/.vimrc.local"))
534 source ~/.vimrc.local
535 endif