]> Tony Duckles's Git Repositories (git.nynim.org) - dotfiles.git/blob - .vimrc
.vimrc: Add NERDTree config
[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=#ffffff
66 " statusline (active vs inactive)
67 highlight StatusLine term=reverse cterm=reverse ctermfg=DarkGrey ctermbg=Grey guifg=#444444 guibg=#aaaaaa
68 highlight StatusLineNC term=reverse cterm=reverse ctermfg=DarkGrey ctermbg=DarkGrey guifg=#444444 guibg=#666666
69 " unprintable chars (listchars)
70 highlight SpecialKey ctermfg=DarkGray ctermbg=Black guifg=#374549 guibg=#010c0e
71
72 " ----------------------------------------------------------------------------
73 " Backups
74 " ----------------------------------------------------------------------------
75
76 set nobackup " do not keep backups after close
77 set nowritebackup " do not keep a backup while working
78 set backupcopy=yes " keep attributes of original file
79 set backupskip=/tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*
80 set directory=.,~/tmp,~/.vim/swap " swap file directory-order
81
82 " ----------------------------------------------------------------------------
83 " UI
84 " ----------------------------------------------------------------------------
85
86 set ruler " show the cursor position all the time
87 set showcmd " display incomplete commands
88 set nolazyredraw " turn off lazy redraw
89 set hidden " keep buffers loaded when hidden
90 set showmode " show mode at bottom of screen
91 set wildmenu " turn on wild menu
92 set wildmode=list:longest,full
93 set cmdheight=2 " command line height
94 set backspace=2 " allow backspacing over everything in insert mode
95 set whichwrap+=<,>,h,l,[,] " backspace and cursor keys wrap to
96 set shortmess=filtIoO " shorten messages
97 set report=0 " tell us about changes
98 set nostartofline " don't jump to the start of line when scrolling
99 set scrolloff=4 " vertcal padding
100 set sidescroll=40 " side-scrolling increment (for nowrap mode)
101 set sidescrolloff=10 " horz padding
102
103 " ----------------------------------------------------------------------------
104 " Visual Cues
105 " ----------------------------------------------------------------------------
106
107 set showmatch " brackets/braces that is
108 set matchtime=5 " duration to show matching brace (1/10 sec)
109 set incsearch " do incremental searching
110 set laststatus=2 " always show the status line
111 set ignorecase " ignore case when searching
112 set smartcase " case-sensitive if search contains an uppercase character
113 set visualbell " shut the heck up
114 set hlsearch " highlight all search matches
115 set list listchars=trail:.,tab:>. " show trailing whitespace and tab chars
116
117 " ----------------------------------------------------------------------------
118 " Status Line
119 " ----------------------------------------------------------------------------
120
121 set statusline=\ %n\ %<%f " buffer #, filename
122 set statusline+=\ %h%m%r " file-state flags
123 set statusline+=%= " left-right divider
124 set statusline+=%{strlen(&fenc)?&fenc:&enc},%{&ff}\ %y " file-encoding, format, type
125 set statusline+=\ %12.(%v,%l/%L%)\ \ %-4P " cursor position, % through file of viewport
126
127 " ----------------------------------------------------------------------------
128 " Text Formatting
129 " ----------------------------------------------------------------------------
130
131 set autoindent " automatic indent new lines
132 set smartindent " be smart about it
133 set nowrap " do not wrap lines
134 set softtabstop=2 " yep, two
135 set shiftwidth=2 " ..
136 set tabstop=4
137 set expandtab " expand tabs to spaces
138 set smarttab " smarter softtab handling
139 set formatoptions+=n " support for numbered/bullet lists
140 set textwidth=0 " no line-wrapping by default
141 set virtualedit=block " allow virtual edit in visual block ..
142
143 " ----------------------------------------------------------------------------
144 " Filename exclusions
145 " ----------------------------------------------------------------------------
146
147 set wildignore+=.hg,.git,.svn " version control directories
148 set wildignore+=*.jpg,*.jpeg,*.bmp,*.gif,*.png " image files
149 set wildignore+=*.o,*.obj,*.exe,*.dll " compiled object files
150 set wildignore+=*.pyc " Python byte code
151 set wildignore+=*.sw? " Vim swap files
152 set wildignore+=.DS_Store " OSX junk
153
154 " ----------------------------------------------------------------------------
155 " Tabs
156 " ----------------------------------------------------------------------------
157
158 if version >= 700
159 set tabpagemax=50 " open 50 tabs max
160 endif
161
162 " ----------------------------------------------------------------------------
163 " Mappings
164 " ----------------------------------------------------------------------------
165
166 let mapleader = ","
167
168 " <F2> to pastetoggle, to turn-off autoindent when pasting from system clipboard
169 nnoremap <F2> :set invpaste paste?<CR>
170 set pastetoggle=<F2>
171
172 " press <Space> to turn off highlighting and clear any message already displayed.
173 nnoremap <silent> <Space> :nohlsearch<Bar>:echo<CR>
174
175 " NERDTreee
176 let NERDTreeShowHidden=1 " show dotfiles by default
177 noremap <F4> :NERDTreeToggle<CR>
178
179 " Gundo
180 nnoremap <F5> :GundoToggle<CR>
181
182 " Command-T
183 noremap <leader>o <Esc>:CommandT<CR>
184 noremap <leader>O <Esc>:CommandTFlush<CR>
185 noremap <leader>m <Esc>:CommandTBuffer<CR>
186
187 " make Y consistent with C (c$) and D (d$)
188 nnoremap Y y$
189
190 " disable default vim regex handling for searching
191 nnoremap / /\v
192 vnoremap / /\v
193
194 " reflow paragraph with Q in normal and visual mode
195 nnoremap Q gqap
196 vnoremap Q gq
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
210 " do not menu with left / right in command line
211 cnoremap <Left> <Space><BS><Left>
212 cnoremap <Right> <Space><BS><Right>
213
214 " buffer navigation
215 nnoremap <C-n> :bnext<CR>
216 nnoremap <C-p> :bprev<CR>
217
218 " easier split-window movement
219 nnoremap <C-h> <C-w>h
220 nnoremap <C-j> <C-w>j
221 nnoremap <C-k> <C-w>k
222 nnoremap <C-l> <C-w>l
223
224 " quickly edit/reload vimrc
225 nmap <silent> <leader>ev :edit $MYVIMRC<CR>
226 nmap <silent> <leader>sv :source $MYVIMRC<CR>
227
228 " upper/lower word
229 nmap <leader>u mQviwU`Q
230 nmap <leader>l mQviwu`Q
231
232 " upper/lower first char of word
233 nmap <leader>U mQgewvU`Q
234 nmap <leader>L mQgewvu`Q
235
236 " cd to the directory containing the file in the buffer
237 nmap <silent> <leader>cd :lcd %:h<CR>
238
239 " set text wrapping toggles
240 nmap <silent> <leader>tw :set invwrap<CR>:set wrap?<CR>
241
242 " find merge conflict markers
243 nmap <silent> <leader>fc <ESC>/\v^[<=>]{7}( .*\|$)<CR>
244
245 " toggle hlsearch with <leader>hs
246 nmap <silent> <leader>hs :set hlsearch! hlsearch?<CR>
247
248 " strip all trailing whitespace in file
249 function! StripWhitespace ()
250 exec ':%s/ \+$//gc'
251 endfunction
252 map <leader>s :call StripWhitespace ()<CR>
253
254 " ----------------------------------------------------------------------------
255 " Auto Commands
256 " ----------------------------------------------------------------------------
257
258 " jump to last position of buffer when opening (but not for commit messages)
259 au BufReadPost * if &filetype !~ '^git\c' && line("'\"") > 0 && line("'\"") <= line("$") |
260 \ exe "normal g'\"" | endif
261
262 " ----------------------------------------------------------------------------
263 " PATH on MacOS X
264 " ----------------------------------------------------------------------------
265
266 if system('uname') =~ 'Darwin'
267 let $PATH = $HOME .
268 \ '/usr/local/bin:/usr/local/sbin:' .
269 \ '/usr/pkg/bin:' .
270 \ '/opt/local/bin:/opt/local/sbin:' .
271 \ $PATH
272 endif
273
274 " ---------------------------------------------------------------------------
275 " File Types
276 " ---------------------------------------------------------------------------
277
278 " sh config
279 au Filetype sh,bash set ts=4 sts=4 sw=4 expandtab
280 let g:is_bash = 1
281 " git commit message
282 au Filetype gitcommit set tw=68 spell
283 " html variants
284 au Filetype html,xml,xsl,rhtml source $HOME/.vim/scripts/closetag.vim
285 " don't use cindent for javascript
286 au FileType javascript setlocal nocindent
287 " use Octopress syntax-highlighting for *.markdown files
288 au BufNewFile,BufRead *.markdown set filetype=octopress
289 " in Makefiles, use real tabs not tabs expanded to spaces
290 au FileType make setlocal noexpandtab
291
292 " --------------------------------------------------------------------------
293 " ManPageView
294 " --------------------------------------------------------------------------
295
296 let g:manpageview_pgm= 'man -P "/usr/bin/less -is"'
297 let $MANPAGER = '/usr/bin/less -is'
298