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