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