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