scrooloose / vimfiles

The ~/.vim directory that we share at work

vimfiles / vimrc
63af46f3 » scrooloose 2008-09-20 add the useful parts of my ... 1 "Use Vim settings, rather then Vi settings (much better!).
2 "This must be first, because it changes other options as a side effect.
3 set nocompatible
4
5 "allow backspacing over everything in insert mode
6 set backspace=indent,eol,start
7
8 "store lots of :cmdline history
9 set history=1000
10
11 set showcmd "show incomplete cmds down the bottom
12 set showmode "show current mode down the bottom
13
14 set incsearch "find the next match as we type the search
15 set hlsearch "hilight searches by default
16
17 set nowrap "dont wrap lines
18 set linebreak "wrap lines at convenient points
19
20 "statusline setup
65b60db8 » scrooloose 2008-11-30 display full path on status... 21 set statusline=%f "tail of the filename
9e25fad6 » scrooloose 2009-01-31 only show &ff and &fenc if ... 22
23 "display a warning if fileformat isnt unix
24 set statusline+=%#warningmsg#
25 set statusline+=%{&ff!='unix'?'['.&ff.']':''}
26 set statusline+=%*
27
28 "display a warning if file encoding isnt utf-8
29 set statusline+=%#warningmsg#
410f2f92 » scrooloose 2009-02-01 dont show empty brackets wh... 30 set statusline+=%{(&fenc!='utf-8'&&&fenc!='')?'['.&fenc.']':''}
9e25fad6 » scrooloose 2009-01-31 only show &ff and &fenc if ... 31 set statusline+=%*
32
63af46f3 » scrooloose 2008-09-20 add the useful parts of my ... 33 set statusline+=%h "help file flag
34 set statusline+=%y "filetype
26a67929 » scrooloose 2008-10-29 make the statusline own harder 35 set statusline+=%r "read only flag
36 set statusline+=%m "modified flag
03cf502e » scrooloose 2008-10-27 make the statusline own harder 37
9f5a0fdc » scrooloose 2008-10-28 maket the tab warning on th... 38 "display a warning if &et is wrong, or we have mixed-indenting
03cf502e » scrooloose 2008-10-27 make the statusline own harder 39 set statusline+=%#error#
40 set statusline+=%{StatuslineTabWarning()}
41 set statusline+=%*
42
26a67929 » scrooloose 2008-10-29 make the statusline own harder 43 set statusline+=%{StatuslineTrailingSpaceWarning()}
07d5ca1e » scrooloose 2008-11-18 error highlight display the... 44
0596fefb » scrooloose 2009-06-18 add a statusline warning if... 45 set statusline+=%{StatuslineLongLineWarning()}
46
a747a2b8 » scrooloose 2009-06-28 completely refactor the syn... 47 set statusline+=%#warningmsg#
48 set statusline+=%{StatuslineSyntaxWarning()}
49 set statusline+=%*
50
07d5ca1e » scrooloose 2008-11-18 error highlight display the... 51 "display a warning if &paste is set
52 set statusline+=%#error#
53 set statusline+=%{&paste?'[paste]':''}
54 set statusline+=%*
55
63af46f3 » scrooloose 2008-09-20 add the useful parts of my ... 56 set statusline+=%= "left/right separator
26a67929 » scrooloose 2008-10-29 make the statusline own harder 57 set statusline+=%{StatuslineCurrentHighlight()}\ \ "current highlight
63af46f3 » scrooloose 2008-09-20 add the useful parts of my ... 58 set statusline+=%c, "cursor column
59 set statusline+=%l/%L "cursor line/total lines
60 set statusline+=\ %P "percent through file
61 set laststatus=2
62
26a67929 » scrooloose 2008-10-29 make the statusline own harder 63 "recalculate the trailing whitespace warning when idle, and after saving
64 autocmd cursorhold,bufwritepost * unlet! b:statusline_trailing_space_warning
65
66 "return '[\s]' if trailing white space is detected
67 "return '' otherwise
68 function! StatuslineTrailingSpaceWarning()
69 if !exists("b:statusline_trailing_space_warning")
70 if search('\s\+$', 'nw') != 0
71 let b:statusline_trailing_space_warning = '[\s]'
72 else
73 let b:statusline_trailing_space_warning = ''
74 endif
75 endif
76 return b:statusline_trailing_space_warning
77 endfunction
78
79
80 "return the syntax highlight group under the cursor ''
ce89cd03 » scrooloose 2008-10-07 add hilight group under cur... 81 function! StatuslineCurrentHighlight()
82 let name = synIDattr(synID(line('.'),col('.'),1),'name')
26a67929 » scrooloose 2008-10-29 make the statusline own harder 83 if name == ''
84 return ''
85 else
86 return '[' . name . ']'
ce89cd03 » scrooloose 2008-10-07 add hilight group under cur... 87 endif
88 endfunction
89
9f5a0fdc » scrooloose 2008-10-28 maket the tab warning on th... 90 "recalculate the tab warning flag when idle and after writing
91 autocmd cursorhold,bufwritepost * unlet! b:statusline_tab_warning
92
93 "return '[&et]' if &et is set wrong
94 "return '[mixed-indenting]' if spaces and tabs are used to indent
95 "return an empty string if everything is fine
03cf502e » scrooloose 2008-10-27 make the statusline own harder 96 function! StatuslineTabWarning()
9f5a0fdc » scrooloose 2008-10-28 maket the tab warning on th... 97 if !exists("b:statusline_tab_warning")
d2bd0034 » scrooloose 2008-11-01 update statusline hax 98 let tabs = search('^\t', 'nw') != 0
99 let spaces = search('^ ', 'nw') != 0
9f5a0fdc » scrooloose 2008-10-28 maket the tab warning on th... 100
101 if tabs && spaces
102 let b:statusline_tab_warning = '[mixed-indenting]'
103 elseif (spaces && !&et) || (tabs && &et)
104 let b:statusline_tab_warning = '[&et]'
105 else
106 let b:statusline_tab_warning = ''
107 endif
03cf502e » scrooloose 2008-10-27 make the statusline own harder 108 endif
9f5a0fdc » scrooloose 2008-10-28 maket the tab warning on th... 109 return b:statusline_tab_warning
03cf502e » scrooloose 2008-10-27 make the statusline own harder 110 endfunction
111
a747a2b8 » scrooloose 2009-06-28 completely refactor the syn... 112 "load all the syntax checkers
113 runtime! syntax_checkers/*.vim
114
115 "recalculate the syntax warning when saving and changing filetype
116 autocmd bufwritepost,filetype * unlet! b:statusline_syntax_warning
117
118 "return [syntax:X] if syntax errors are detected in the buffer, where X is the
119 "line number of the first error.
120 "return '' if no errors or if no syntax checker exists for the current filetype
121 function! StatuslineSyntaxWarning()
122 if !exists("b:statusline_syntax_warning")
123 let b:statusline_syntax_warning = ''
124
3a9c6c84 » scrooloose 2009-06-30 make syntax checking handle... 125 "if &ft is e.g. ruby.sinatra then syntax check both filetypes
126 for ft in split(&ft, '\.')
127
128 if exists("*CheckSyntax_" . ft) && filereadable(expand("%"))
129 let first_err_line = CheckSyntax_{ft}()
130 if first_err_line != 0
131 let b:statusline_syntax_warning = '[syntax:' . first_err_line . ']'
132 break
133 endif
a747a2b8 » scrooloose 2009-06-28 completely refactor the syn... 134 endif
3a9c6c84 » scrooloose 2009-06-30 make syntax checking handle... 135 endfor
a747a2b8 » scrooloose 2009-06-28 completely refactor the syn... 136 endif
137 return b:statusline_syntax_warning
138 endfunction
139
140
0596fefb » scrooloose 2009-06-18 add a statusline warning if... 141 "recalculate the long line warning when idle and after saving
142 autocmd cursorhold,bufwritepost * unlet! b:statusline_long_line_warning
143
dcfd9218 » scrooloose 2009-06-26 bugfix and awesomify the lo... 144 "return a warning for "long lines" where "long" is either &textwidth or 80 (if
145 "no &textwidth is set)
146 "
147 "return '' if no long lines
d47587e2 » scrooloose 2009-06-27 decompose the statusline lo... 148 "return '[#x,my,$z] if long lines are found, were x is the number of long
149 "lines, y is the median length of the long lines and z is the length of the
150 "longest line
0596fefb » scrooloose 2009-06-18 add a statusline warning if... 151 function! StatuslineLongLineWarning()
152 if !exists("b:statusline_long_line_warning")
d47587e2 » scrooloose 2009-06-27 decompose the statusline lo... 153 let long_line_lens = s:LongLines()
0596fefb » scrooloose 2009-06-18 add a statusline warning if... 154
e2ef6c82 » scrooloose 2009-06-27 make the long line warning ... 155 if len(long_line_lens) > 0
d47587e2 » scrooloose 2009-06-27 decompose the statusline lo... 156 let b:statusline_long_line_warning = "[" .
157 \ '#' . len(long_line_lens) . "," .
158 \ 'm' . s:Median(long_line_lens) . "," .
159 \ '$' . max(long_line_lens) . "]"
0596fefb » scrooloose 2009-06-18 add a statusline warning if... 160 else
161 let b:statusline_long_line_warning = ""
162 endif
163 endif
164 return b:statusline_long_line_warning
165 endfunction
166
d47587e2 » scrooloose 2009-06-27 decompose the statusline lo... 167 "return a list containing the lengths of the long lines in this buffer
168 function! s:LongLines()
169 let threshold = (&tw ? &tw : 80)
170 let spaces = repeat(" ", &ts)
171
172 let long_line_lens = []
173
174 let i = 1
175 while i <= line("$")
176 let len = strlen(substitute(getline(i), '\t', spaces, 'g'))
177 if len > threshold
178 call add(long_line_lens, len)
179 endif
180 let i += 1
181 endwhile
182
183 return long_line_lens
184 endfunction
185
e2ef6c82 » scrooloose 2009-06-27 make the long line warning ... 186 "find the median of the given array of numbers
187 function! s:Median(nums)
188 let nums = sort(a:nums)
189 let l = len(nums)
190
191 if l % 2 == 1
192 let i = (l-1) / 2
193 return nums[i]
194 else
195 return (nums[l/2] + nums[(l/2)-1]) / 2
196 endif
197 endfunction
198
63af46f3 » scrooloose 2008-09-20 add the useful parts of my ... 199 "indent settings
200 set shiftwidth=4
201 set softtabstop=4
202 set expandtab
203 set autoindent
204
205 "folding settings
206 set foldmethod=indent "fold based on indent
207 set foldnestmax=3 "deepest fold is 3 levels
208 set nofoldenable "dont fold by default
209
210 set wildmode=list:longest "make cmdline tab completion similar to bash
211 set wildmenu "enable ctrl-n and ctrl-p to scroll thru matches
a695102a » scrooloose 2008-10-29 set wildignore 212 set wildignore=*.o,*.obj,*~ "stuff to ignore when tab completing
63af46f3 » scrooloose 2008-09-20 add the useful parts of my ... 213
214 "display tabs and trailing spaces
215 set list
216 set listchars=tab:▷⋅,trail:⋅,nbsp:⋅
217
218 set formatoptions-=o "dont continue comments when pushing o/O
219
220 "vertical/horizontal scroll off settings
221 set scrolloff=3
222 set sidescrolloff=7
223 set sidescroll=1
224
225 "load ftplugins and indent files
226 filetype plugin on
227 filetype indent on
228
229 "turn on syntax highlighting
230 syntax on
231
232 "some stuff to get the mouse going in term
233 set mouse=a
234 set ttymouse=xterm2
235
236 "tell the term has 256 colors
237 set t_Co=256
238
239 "hide buffers when not displayed
240 set hidden
241
332c6778 » scrooloose 2008-10-06 dont source csapprox if we ... 242 "dont load csapprox if we no gui support - silences an annoying warning
243 if !has("gui")
244 let g:CSApprox_loaded = 1
245 endif
246
63af46f3 » scrooloose 2008-09-20 add the useful parts of my ... 247 "make <c-l> clear the highlight as well as redraw
248 nnoremap <C-L> :nohls<CR><C-L>
249 inoremap <C-L> <C-O>:nohls<CR>
250
6c1c2aef » scrooloose 2008-10-12 add map to buf explorer 251 "map to bufexplorer
252 nnoremap <C-B> :BufExplorer<cr>
253
28dcbf31 » scrooloose 2008-10-18 add fuzzyfinder textmate st... 254 "map to fuzzy finder text mate stylez
255 nnoremap <c-f> :FuzzyFinderTextMate<CR>
256
63af46f3 » scrooloose 2008-09-20 add the useful parts of my ... 257 "map Q to something useful
258 noremap Q gq
259
260 "make Y consistent with C and D
261 nnoremap Y y$
262
d903f144 » scrooloose 2009-06-07 add snipmate setup to vimrc 263 "snipmate setup
264 source ~/.vim/snippets/support_functions.vim
9f7314c5 » scrooloose 2009-06-17 only load rails snippets if... 265 autocmd vimenter * call s:SetupSnippets()
266 function! s:SetupSnippets()
267
268 "if we're in a rails env then read in the rails snippets
269 if filereadable("./config/environment.rb")
270 call ExtractSnips("~/.vim/snippets/ruby-rails", "ruby")
271 call ExtractSnips("~/.vim/snippets/eruby-rails", "eruby")
272 endif
273
274 call ExtractSnips("~/.vim/snippets/html", "eruby")
275 call ExtractSnips("~/.vim/snippets/html", "xhtml")
276 call ExtractSnips("~/.vim/snippets/html", "php")
277 endfunction
d903f144 » scrooloose 2009-06-07 add snipmate setup to vimrc 278
63af46f3 » scrooloose 2008-09-20 add the useful parts of my ... 279 "visual search mappings
280 function! s:VSetSearch()
281 let temp = @@
282 norm! gvy
283 let @/ = '\V' . substitute(escape(@@, '\'), '\n', '\\n', 'g')
284 let @@ = temp
285 endfunction
286 vnoremap * :<C-u>call <SID>VSetSearch()<CR>//<CR>
287 vnoremap # :<C-u>call <SID>VSetSearch()<CR>??<CR>
288
289
f170376c » scrooloose 2008-09-22 add some more to the vimrc 290 "jump to last cursor position when opening a file
291 "dont do it when writing a commit log entry
63af46f3 » scrooloose 2008-09-20 add the useful parts of my ... 292 autocmd BufReadPost * call SetCursorPosition()
293 function! SetCursorPosition()
294 if &filetype !~ 'commit\c'
295 if line("'\"") > 0 && line("'\"") <= line("$")
f5bd12f3 » scrooloose 2009-06-07 use normal! and center scre... 296 exe "normal! g`\""
297 normal! zz
63af46f3 » scrooloose 2008-09-20 add the useful parts of my ... 298 endif
299 end
300 endfunction
301
56c3bbcb » scrooloose 2009-06-18 rename HighlightExcessColum... 302 "define :HighlightLongLines command to highlight the offending parts of
303 "lines that are longer than the specified length (defaulting to 80)
304 command! -nargs=? HighlightLongLines call s:HighlightLongLines('<args>')
305 function! s:HighlightLongLines(width)
306 let targetWidth = a:width != '' ? a:width : 79
f170376c » scrooloose 2008-09-22 add some more to the vimrc 307 if targetWidth > 0
56c3bbcb » scrooloose 2009-06-18 rename HighlightExcessColum... 308 exec 'match Todo /\%>' . (targetWidth) . 'v/'
f170376c » scrooloose 2008-09-22 add some more to the vimrc 309 else
56c3bbcb » scrooloose 2009-06-18 rename HighlightExcessColum... 310 echomsg "Usage: HighlightLongLines [natural number]"
f170376c » scrooloose 2008-09-22 add some more to the vimrc 311 endif
312 endfunction