]> Tony Duckles's Git Repositories (git.nynim.org) - dotfiles.git/blob - .vimrc
.vimrc: Enable swap files; scrolloff and sidescroll; comment clean-up
[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 call pathogen#infect() " enable pathogen (plugin bundles)
15 filetype plugin indent on " load filetype plugin
16
17 " ---------------------------------------------------------------------------
18 " Colors / Theme
19 " ---------------------------------------------------------------------------
20
21 if &t_Co > 2 || has("gui_running")
22 if has("terminfo")
23 set t_Co=16
24 set t_AB=\e[%?%p1%{8}%<%t%p1%{40}%+%e%p1%{92}%+%;%dm
25 set t_AF=\e[%?%p1%{8}%<%t%p1%{30}%+%e%p1%{82}%+%;%dm
26 else
27 set t_Co=16
28 set t_Sf=\e[3%dm
29 set t_Sb=\e[4%dm
30 endif
31
32 set background=dark " dark background
33 syntax enable " syntax highligting
34 set hlsearch " highlight all search matches
35 " Press <Space> to turn off highlighting and clear any message already displayed.
36 :nnoremap <silent> <Space> :nohlsearch<Bar>:echo<CR>
37
38 " Define to-do color(s)
39 if !exists("autocmd_colorscheme_loaded")
40 let autocmd_colorscheme_loaded = 1
41 autocmd ColorScheme * highlight TodoRed ctermbg=LightRed guibg=#E01B1B ctermfg=White guifg=#002b37
42 endif
43
44 " Solarized color-scheme
45 let g:solarized_termtrans=1 " Always use terminal's default bg color
46 colorscheme solarized
47
48 " Auto-highlight TODO's
49 if has("autocmd")
50 if v:version > 701
51 autocmd Syntax * call matchadd('TodoRed', '\W\zs\(TODO\)')
52 endif
53 endif
54 endif
55
56 " ---------------------------------------------------------------------------
57 " Highlight
58 " ---------------------------------------------------------------------------
59
60 highlight Comment ctermfg=DarkGrey guifg=#444444
61 highlight StatusLineNC ctermfg=Black ctermbg=DarkGrey cterm=bold
62 highlight StatusLine ctermbg=Black ctermfg=LightGrey
63
64 " ----------------------------------------------------------------------------
65 " Highlight Trailing Whitespace
66 " ----------------------------------------------------------------------------
67
68 set list listchars=trail:.,tab:>.
69 highlight SpecialKey ctermfg=DarkGray ctermbg=Black
70
71 " ----------------------------------------------------------------------------
72 " Backups
73 " ----------------------------------------------------------------------------
74
75 set nobackup " do not keep backups after close
76 set nowritebackup " do not keep a backup while working
77 "set noswapfile " don't keep swp files either
78 set backupdir=$HOME/.vim/backup " store backups under ~/.vim/backup
79 set backupcopy=yes " keep attributes of original file
80 set backupskip=/tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*
81 set directory=~/.vim/swap,~/tmp,. " keep swp files under ~/.vim/swap
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 number " line numbers
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
102 " ----------------------------------------------------------------------------
103 " Visual Cues
104 " ----------------------------------------------------------------------------
105
106 set showmatch " brackets/braces that is
107 set matchtime=5 " duration to show matching brace (1/10 sec)
108 set incsearch " do incremental searching
109 set laststatus=2 " always show the status line
110 set ignorecase " ignore case when searching
111 set smartcase " case-sensitive if search contains an uppercase character
112 set visualbell " shut the heck up
113
114 " ----------------------------------------------------------------------------
115 " Text Formatting
116 " ----------------------------------------------------------------------------
117
118 set autoindent " automatic indent new lines
119 set smartindent " be smart about it
120 set nowrap " do not wrap lines
121 set softtabstop=2 " yep, two
122 set shiftwidth=2 " ..
123 set tabstop=4
124 set expandtab " expand tabs to spaces
125 set nosmarttab " screw tabs
126 set formatoptions+=n " support for numbered/bullet lists
127 "set textwidth=110 " wrap at 110 chars by default
128 set virtualedit=block " allow virtual edit in visual block ..
129
130 " ----------------------------------------------------------------------------
131 " Tabs
132 " ----------------------------------------------------------------------------
133
134 if version >= 700
135 set tabpagemax=50 " open 50 tabs max
136 endif
137
138 " ----------------------------------------------------------------------------
139 " Mappings
140 " ----------------------------------------------------------------------------
141
142 " <F2> to pastetoggle, to turn-off autoindent when pasting from system clipboard
143 nnoremap <F2> :set invpaste paste?<CR>
144 set pastetoggle=<F2>
145 set showmode
146
147 "" <F8>/<Shift>-<F8> to navigation between buffers
148 if version >= 700
149 set switchbuf=usetab
150 nnoremap <F8> :sbnext<CR>
151 nnoremap <S-F8> :sbprevious<CR>
152 endif
153
154 "" quickfix-window mappings
155 "map <F7> :cn<CR>
156 "map <S-F7> :cp<CR>
157 "map <A-F7> :copen<CR>
158
159 "" emacs movement keybindings in insert mode
160 "imap <C-a> <C-o>0
161 "imap <C-e> <C-o>$
162 "map <C-e> $
163 "map <C-a> 0
164
165 " reflow paragraph with Q in normal and visual mode
166 nnoremap Q gqap
167 vnoremap Q gq
168
169 " sane movement with wrap turned on
170 nnoremap j gj
171 nnoremap k gk
172 vnoremap j gj
173 vnoremap k gk
174 nnoremap <Down> gj
175 nnoremap <Up> gk
176 vnoremap <Down> gj
177 vnoremap <Up> gk
178 inoremap <Down> <C-o>gj
179 inoremap <Up> <C-o>gk
180
181 " do not menu with left / right in command line
182 cnoremap <Left> <Space><BS><Left>
183 cnoremap <Right> <Space><BS><Right>
184
185 " ----------------------------------------------------------------------------
186 " Auto Commands
187 " ----------------------------------------------------------------------------
188
189 " jump to last position of buffer when opening
190 au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") |
191 \ exe "normal g'\"" | endif
192
193 " don't use cindent for javascript
194 autocmd FileType javascript setlocal nocindent
195
196 " ----------------------------------------------------------------------------
197 " LookupFile
198 " ----------------------------------------------------------------------------
199
200 "let g:LookupFile_TagExpr = '".ftags"'
201 "let g:LookupFile_MinPatLength = 2
202 "let g:LookupFile_ShowFiller = 0 " fix menu flashiness
203 "let g:LookupFile_PreservePatternHistory = 1 " preserve sorted history?
204 "let g:LookupFile_PreserveLastPattern = 0 " start with last pattern?
205 "
206 "nmap <unique> <silent> <D-f> <Plug>LookupFile
207 "imap <unique> <silent> <D-f> <C-O><Plug>LookupFile
208
209 " ----------------------------------------------------------------------------
210 " PATH on MacOS X
211 " ----------------------------------------------------------------------------
212
213 if system('uname') =~ 'Darwin'
214 let $PATH = $HOME .
215 \ '/usr/local/bin:/usr/local/sbin:' .
216 \ '/usr/pkg/bin:' .
217 \ '/opt/local/bin:/opt/local/sbin:' .
218 \ $PATH
219 endif
220
221 " ---------------------------------------------------------------------------
222 " sh config
223 " ---------------------------------------------------------------------------
224
225 au Filetype sh,bash set ts=4 sts=4 sw=4 expandtab
226 let g:is_bash = 1
227
228 " ---------------------------------------------------------------------------
229 " Misc mappings
230 " ---------------------------------------------------------------------------
231
232 "map ,f :tabnew <cfile><CR>
233 "map ,d :e %:h/<CR>
234 "map ,dt :tabnew %:h/<CR>
235
236 "" I use these commands in my TODO file
237 "map ,a o<ESC>:r!date +'\%A, \%B \%d, \%Y'<CR>:r!date +'\%A, \%B \%d, \%Y' \| sed 's/./-/g'<CR>A<CR><ESC>
238 "map ,o o[ ]
239 "map ,O O[ ]
240 "map ,x :s/^\[ \]/[x]/<CR>
241 "map ,X :s/^\[x\]/[ ]/<CR>
242
243 " ---------------------------------------------------------------------------
244 " Strip all trailing whitespace in file
245 " ---------------------------------------------------------------------------
246
247 function! StripWhitespace ()
248 exec ':%s/ \+$//gc'
249 endfunction
250 map ,s :call StripWhitespace ()<CR>
251
252 " ---------------------------------------------------------------------------
253 " File Types
254 " ---------------------------------------------------------------------------
255
256 au Filetype gitcommit set tw=68 spell
257 "au Filetype html,xml,xsl,rhtml source $HOME/.vim/scripts/closetag.vim
258
259 " --------------------------------------------------------------------------
260 " ManPageView
261 " --------------------------------------------------------------------------
262
263 let g:manpageview_pgm= 'man -P "/usr/bin/less -is"'
264 let $MANPAGER = '/usr/bin/less -is'
265