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