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