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