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