]> Tony Duckles's Git Repositories (git.nynim.org) - dotfiles.git/blob - .vimrc
Merge remote 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 " vertcal 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:Powerline_theme = 'default' " standard segments
129 let g:Powerline_colorscheme = 'solarized16' " modified solarized16 theme
130 let g:Powerline_stl_path_style = 'relative' " show parent folders
131 let g:Powerline_cache_enabled = 0 " don't cache
132
133 " ----------------------------------------------------------------------------
134 " Text Formatting
135 " ----------------------------------------------------------------------------
136
137 set autoindent " automatic indent new lines
138 set smartindent " be smart about it
139 set nowrap " do not wrap lines
140 set softtabstop=2 " yep, two
141 set shiftwidth=2 " ..
142 set tabstop=4
143 set expandtab " expand tabs to spaces
144 set smarttab " smarter softtab handling
145 set formatoptions+=n " support for numbered/bullet lists
146 set textwidth=0 " no line-wrapping by default
147 set virtualedit=block " allow virtual edit in visual block ..
148
149 " ----------------------------------------------------------------------------
150 " Filename exclusions
151 " ----------------------------------------------------------------------------
152
153 set wildignore+=.hg,.git,.svn " version control directories
154 set wildignore+=*.jpg,*.jpeg,*.bmp,*.gif,*.png " image files
155 set wildignore+=*.o,*.obj,*.exe,*.dll " compiled object files
156 set wildignore+=*.pyc " Python byte code
157 set wildignore+=*.sw? " Vim swap files
158 set wildignore+=.DS_Store " OSX junk
159
160 " ----------------------------------------------------------------------------
161 " Tabs
162 " ----------------------------------------------------------------------------
163
164 if version >= 700
165 set tabpagemax=50 " open 50 tabs max
166 endif
167
168 " ----------------------------------------------------------------------------
169 " Mappings
170 " ----------------------------------------------------------------------------
171
172 " movement based on display lines not physical lines (sane movement with wrap turned on)
173 nnoremap j gj
174 nnoremap k gk
175 vnoremap j gj
176 vnoremap k gk
177 nnoremap <Down> gj
178 nnoremap <Up> gk
179 vnoremap <Down> gj
180 vnoremap <Up> gk
181 inoremap <Down> <C-o>gj
182 inoremap <Up> <C-o>gk
183 " buffer navigation
184 nnoremap <C-n> :bnext<CR>
185 nnoremap <C-p> :bprev<CR>
186 " easier moving cursor between split-windows
187 nnoremap <C-h> <C-w>h
188 nnoremap <C-j> <C-w>j
189 nnoremap <C-k> <C-w>k
190 nnoremap <C-l> <C-w>l
191 " do not menu with left / right in command line
192 cnoremap <Left> <Space><BS><Left>
193 cnoremap <Right> <Space><BS><Right>
194
195 " reflow paragraph with Q in normal and visual mode
196 nnoremap Q gqap
197 vnoremap Q gq
198 " make Y consistent with C (c$) and D (d$)
199 nnoremap Y y$
200 " disable default vim regex handling for searching
201 nnoremap / /\v
202 vnoremap / /\v
203 " reselect visual block after indent/outdent
204 vnoremap < <gv
205 vnoremap > >gv
206
207 " <Space> to turn off highlighting and clear any message already displayed.
208 nnoremap <silent> <Space> :nohlsearch<Bar>:echo<CR>
209 " <F2> to pastetoggle, to turn-off autoindent when pasting from system clipboard
210 nnoremap <F2> :set paste! paste?<CR>
211 " <F4> to toggle NERDTree
212 nnoremap <F4> :NERDTreeToggle<CR>
213 " <F5> to toggle Gundo
214 nnoremap <F5> :GundoToggle<CR>
215 " <F7> to toggle spell-check
216 nnoremap <F7> :setlocal spell! spelllang=en_us spell?<CR>
217 inoremap <F7> <C-o>:setlocal spell! spelllang=en_us spell?<CR>
218
219 " leader-based keyboard shortcuts
220 let mapleader = ","
221 " CtrlP
222 nmap <leader>b :CtrlPBuffer<CR>
223 nmap <leader>o :CtrlP<CR>
224 nmap <leader>O :CtrlPClearCache<CR>:CtrlP<CR>
225 " NERDTree
226 nmap <leader>d :NERDTreeToggle<CR>
227 nmap <leader>f :NERDTreeFind<CR>
228 " Fugitive (Git)
229 nmap <leader>gb :Gblame<CR>
230 nmap <leader>gs :Gstatus<CR>
231 nmap <leader>gd :Gdiff<CR>
232 nmap <leader>gl :Glog<CR>
233 nmap <leader>gc :Gcommit<CR>
234 nmap <leader>gp :Gpush<CR>
235 " cd to the directory containing the file in the buffer
236 nmap <leader>cd :lcd %:h<CR>
237 " toggle diffmode for a buffer
238 nmap <leader>df :call DiffToggle()<CR>
239 function! DiffToggle()
240 if &diff
241 diffoff
242 else
243 diffthis
244 endif
245 endfunction
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>u mQviwU`Q
255 nmap <leader>l mQviwu`Q
256 " upper/lower first char of word
257 nmap <leader>U mQgewvU`Q
258 nmap <leader>L mQgewvu`Q
259 " strip all trailing whitespace in file
260 nmap <leader>s :call whitespace#strip_trailing()<CR>
261 " toggle spell-check
262 nmap <leader>sp :setlocal spell! spelllang=en_us spell?<CR>
263 " set text wrapping toggles
264 nmap <leader>tw :set wrap! wrap?<CR>
265 " set list-whitespace-chars toggle
266 nmap <leader>ws :set list! list?<CR>
267
268 " ----------------------------------------------------------------------------
269 " Plugin Settings
270 " ----------------------------------------------------------------------------
271
272 " NERDTree
273 let NERDTreeShowHidden=1 " show dotfiles by default
274 " Ctrl-P
275 let g:ctrlp_map = ''
276 let g:ctrlp_show_hidden = 1
277
278 " ----------------------------------------------------------------------------
279 " Auto Commands
280 " ----------------------------------------------------------------------------
281
282 " jump to last position of buffer when opening (but not for commit messages)
283 au BufReadPost * if &filetype !~ '^git\c' && line("'\"") > 0 && line("'\"") <= line("$") |
284 \ exe "normal g'\"" | endif
285
286 " ----------------------------------------------------------------------------
287 " PATH on MacOS X
288 " ----------------------------------------------------------------------------
289
290 if system('uname') =~ 'Darwin'
291 let $PATH = $HOME .
292 \ '/usr/local/bin:/usr/local/sbin:' .
293 \ '/usr/pkg/bin:' .
294 \ '/opt/local/bin:/opt/local/sbin:' .
295 \ $PATH
296 endif
297
298 " ---------------------------------------------------------------------------
299 " File Types
300 " ---------------------------------------------------------------------------
301
302 " sh config
303 au Filetype sh,bash set ts=4 sts=4 sw=4 expandtab
304 let g:is_bash = 1
305 " git commit message
306 au Filetype gitcommit set tw=68 spell spelllang=en_us
307 " html variants
308 au Filetype html,xml,xsl,rhtml source $HOME/.vim/scripts/closetag.vim
309 " don't use cindent for javascript
310 au FileType javascript setlocal nocindent
311 " use Octopress syntax-highlighting for *.markdown files
312 au BufNewFile,BufRead *.markdown set filetype=octopress spell spelllang=en_us
313 " in Makefiles, use real tabs not tabs expanded to spaces
314 au FileType make setlocal noexpandtab
315
316 " --------------------------------------------------------------------------
317 " ManPageView
318 " --------------------------------------------------------------------------
319
320 let g:manpageview_pgm= 'man -P "/usr/bin/less -is"'
321 let $MANPAGER = '/usr/bin/less -is'
322