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