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