]> Tony Duckles's Git Repositories (git.nynim.org) - dotfiles.git/blob - .vimrc
.iterm2/colors: Tweaks to solarized-ansi
[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=Black 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 " <Space> to turn off highlighting and clear any message already displayed.
169 nnoremap <silent> <Space> :nohlsearch<Bar>:echo<CR>
170
171 " <F2> to pastetoggle, to turn-off autoindent when pasting from system clipboard
172 nnoremap <F2> :set invpaste paste?<CR>
173 set pastetoggle=<F2>
174
175 " <F4> to toggle NERDTreee
176 let NERDTreeShowHidden=1 " show dotfiles by default
177 noremap <F4> :NERDTreeToggle<CR>
178
179 " <F5> to toggle Gundo
180 nnoremap <F5> :GundoToggle<CR>
181
182 " <F7> to toggle spell-check
183 nnoremap <F7> :setlocal spell! spelllang=en_us spell?<CR>
184 inoremap <F7> <C-o>:setlocal spell! spelllang=en_us spell?<CR>
185
186 " Command-T
187 noremap <leader>o <Esc>:CommandT<CR>
188 noremap <leader>O <Esc>:CommandTFlush<CR>
189 noremap <leader>m <Esc>:CommandTBuffer<CR>
190
191 " make Y consistent with C (c$) and D (d$)
192 nnoremap Y y$
193
194 " disable default vim regex handling for searching
195 nnoremap / /\v
196 vnoremap / /\v
197
198 " reflow paragraph with Q in normal and visual mode
199 nnoremap Q gqap
200 vnoremap Q gq
201
202 " movement based on display lines not physical lines (sane movement with wrap turned on)
203 nnoremap j gj
204 nnoremap k gk
205 vnoremap j gj
206 vnoremap k gk
207 nnoremap <Down> gj
208 nnoremap <Up> gk
209 vnoremap <Down> gj
210 vnoremap <Up> gk
211 inoremap <Down> <C-o>gj
212 inoremap <Up> <C-o>gk
213
214 " do not menu with left / right in command line
215 cnoremap <Left> <Space><BS><Left>
216 cnoremap <Right> <Space><BS><Right>
217
218 " buffer navigation
219 nnoremap <C-n> :bnext<CR>
220 nnoremap <C-p> :bprev<CR>
221
222 " easier split-window movement
223 nnoremap <C-h> <C-w>h
224 nnoremap <C-j> <C-w>j
225 nnoremap <C-k> <C-w>k
226 nnoremap <C-l> <C-w>l
227
228 " quickly edit/reload vimrc
229 nmap <silent> <leader>ev :edit $MYVIMRC<CR>
230 nmap <silent> <leader>sv :source $MYVIMRC<CR>
231
232 " upper/lower word
233 nmap <leader>u mQviwU`Q
234 nmap <leader>l mQviwu`Q
235
236 " upper/lower first char of word
237 nmap <leader>U mQgewvU`Q
238 nmap <leader>L mQgewvu`Q
239
240 " cd to the directory containing the file in the buffer
241 nmap <silent> <leader>cd :lcd %:h<CR>
242
243 " set text wrapping toggles
244 nmap <silent> <leader>tw :set invwrap<CR>:set wrap?<CR>
245
246 " find merge conflict markers
247 nmap <silent> <leader>fc <ESC>/\v^[<=>]{7}( .*\|$)<CR>
248
249 " toggle hlsearch with <leader>hs
250 nmap <silent> <leader>hs :set hlsearch! hlsearch?<CR>
251
252 " strip all trailing whitespace in file
253 function! StripWhitespace ()
254 exec ':%s/ \+$//gc'
255 endfunction
256 map <leader>s :call StripWhitespace ()<CR>
257
258 " ----------------------------------------------------------------------------
259 " Auto Commands
260 " ----------------------------------------------------------------------------
261
262 " jump to last position of buffer when opening (but not for commit messages)
263 au BufReadPost * if &filetype !~ '^git\c' && line("'\"") > 0 && line("'\"") <= line("$") |
264 \ exe "normal g'\"" | endif
265
266 " ----------------------------------------------------------------------------
267 " PATH on MacOS X
268 " ----------------------------------------------------------------------------
269
270 if system('uname') =~ 'Darwin'
271 let $PATH = $HOME .
272 \ '/usr/local/bin:/usr/local/sbin:' .
273 \ '/usr/pkg/bin:' .
274 \ '/opt/local/bin:/opt/local/sbin:' .
275 \ $PATH
276 endif
277
278 " ---------------------------------------------------------------------------
279 " File Types
280 " ---------------------------------------------------------------------------
281
282 " sh config
283 au Filetype sh,bash set ts=4 sts=4 sw=4 expandtab
284 let g:is_bash = 1
285 " git commit message
286 au Filetype gitcommit set tw=68 spell spelllang=en_us
287 " html variants
288 au Filetype html,xml,xsl,rhtml source $HOME/.vim/scripts/closetag.vim
289 " don't use cindent for javascript
290 au FileType javascript setlocal nocindent
291 " use Octopress syntax-highlighting for *.markdown files
292 au BufNewFile,BufRead *.markdown set filetype=octopress spell spelllang=en_us
293 " in Makefiles, use real tabs not tabs expanded to spaces
294 au FileType make setlocal noexpandtab
295
296 " --------------------------------------------------------------------------
297 " ManPageView
298 " --------------------------------------------------------------------------
299
300 let g:manpageview_pgm= 'man -P "/usr/bin/less -is"'
301 let $MANPAGER = '/usr/bin/less -is'
302