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