Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 316 lines (249 sloc) 8.947 kB
63af46f @scrooloose add the useful parts of my vimrc
authored
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
65b60db @scrooloose display full path on statusline
authored
21 set statusline=%f "tail of the filename
9e25fad @scrooloose only show &ff and &fenc if they arent unix/utf-8
authored
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#
410f2f9 @scrooloose dont show empty brackets when theres no &fenc
authored
30 set statusline+=%{(&fenc!='utf-8'&&&fenc!='')?'['.&fenc.']':''}
9e25fad @scrooloose only show &ff and &fenc if they arent unix/utf-8
authored
31 set statusline+=%*
32
63af46f @scrooloose add the useful parts of my vimrc
authored
33 set statusline+=%h "help file flag
34 set statusline+=%y "filetype
26a6792 @scrooloose make the statusline own harder
authored
35 set statusline+=%r "read only flag
36 set statusline+=%m "modified flag
03cf502 @scrooloose make the statusline own harder
authored
37
9f5a0fd @scrooloose maket the tab warning on the stl own more
authored
38 "display a warning if &et is wrong, or we have mixed-indenting
03cf502 @scrooloose make the statusline own harder
authored
39 set statusline+=%#error#
40 set statusline+=%{StatuslineTabWarning()}
41 set statusline+=%*
42
26a6792 @scrooloose make the statusline own harder
authored
43 set statusline+=%{StatuslineTrailingSpaceWarning()}
07d5ca1 @scrooloose error highlight display the [paste] flag
authored
44
0596fef @scrooloose add a statusline warning if long lines are detected
authored
45 set statusline+=%{StatuslineLongLineWarning()}
46
a747a2b @scrooloose completely refactor the syntax checking
authored
47 set statusline+=%#warningmsg#
facb166 @scrooloose use the syntastic syntax checking plugin
authored
48 set statusline+=%{SyntasticStatuslineFlag()}
a747a2b @scrooloose completely refactor the syntax checking
authored
49 set statusline+=%*
50
07d5ca1 @scrooloose error highlight display the [paste] flag
authored
51 "display a warning if &paste is set
52 set statusline+=%#error#
53 set statusline+=%{&paste?'[paste]':''}
54 set statusline+=%*
55
63af46f @scrooloose add the useful parts of my vimrc
authored
56 set statusline+=%= "left/right separator
26a6792 @scrooloose make the statusline own harder
authored
57 set statusline+=%{StatuslineCurrentHighlight()}\ \ "current highlight
63af46f @scrooloose add the useful parts of my vimrc
authored
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
26a6792 @scrooloose make the statusline own harder
authored
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")
b4ad446 @scrooloose supress statusbar warnings if the file is not modifiable
authored
70
71 if !&modifiable
72 let b:statusline_trailing_space_warning = ''
73 return b:statusline_trailing_space_warning
74 endif
75
26a6792 @scrooloose make the statusline own harder
authored
76 if search('\s\+$', 'nw') != 0
77 let b:statusline_trailing_space_warning = '[\s]'
78 else
79 let b:statusline_trailing_space_warning = ''
80 endif
81 endif
82 return b:statusline_trailing_space_warning
83 endfunction
84
85
86 "return the syntax highlight group under the cursor ''
ce89cd0 @scrooloose add hilight group under cursor to statusline
authored
87 function! StatuslineCurrentHighlight()
88 let name = synIDattr(synID(line('.'),col('.'),1),'name')
26a6792 @scrooloose make the statusline own harder
authored
89 if name == ''
90 return ''
91 else
92 return '[' . name . ']'
ce89cd0 @scrooloose add hilight group under cursor to statusline
authored
93 endif
94 endfunction
95
9f5a0fd @scrooloose maket the tab warning on the stl own more
authored
96 "recalculate the tab warning flag when idle and after writing
97 autocmd cursorhold,bufwritepost * unlet! b:statusline_tab_warning
98
99 "return '[&et]' if &et is set wrong
100 "return '[mixed-indenting]' if spaces and tabs are used to indent
101 "return an empty string if everything is fine
03cf502 @scrooloose make the statusline own harder
authored
102 function! StatuslineTabWarning()
9f5a0fd @scrooloose maket the tab warning on the stl own more
authored
103 if !exists("b:statusline_tab_warning")
b4ad446 @scrooloose supress statusbar warnings if the file is not modifiable
authored
104 let b:statusline_tab_warning = ''
105
106 if !&modifiable
107 return b:statusline_tab_warning
108 endif
109
d2bd003 @scrooloose update statusline hax
authored
110 let tabs = search('^\t', 'nw') != 0
9f5a0fd @scrooloose maket the tab warning on the stl own more
authored
111
01e5c6e @scrooloose another fix to the intent stl flag
authored
112 "find spaces that arent used as alignment in the first indent column
113 let spaces = search('^ \{' . &ts . ',}[^\t]', 'nw') != 0
3ae194e @scrooloose upgrade the statsline indent warning
authored
114
9f5a0fd @scrooloose maket the tab warning on the stl own more
authored
115 if tabs && spaces
01e5c6e @scrooloose another fix to the intent stl flag
authored
116 let b:statusline_tab_warning = '[mixed-indenting]'
9f5a0fd @scrooloose maket the tab warning on the stl own more
authored
117 elseif (spaces && !&et) || (tabs && &et)
118 let b:statusline_tab_warning = '[&et]'
119 endif
03cf502 @scrooloose make the statusline own harder
authored
120 endif
9f5a0fd @scrooloose maket the tab warning on the stl own more
authored
121 return b:statusline_tab_warning
03cf502 @scrooloose make the statusline own harder
authored
122 endfunction
123
0596fef @scrooloose add a statusline warning if long lines are detected
authored
124 "recalculate the long line warning when idle and after saving
125 autocmd cursorhold,bufwritepost * unlet! b:statusline_long_line_warning
126
dcfd921 @scrooloose bugfix and awesomify the long line warning
authored
127 "return a warning for "long lines" where "long" is either &textwidth or 80 (if
128 "no &textwidth is set)
129 "
130 "return '' if no long lines
d47587e @scrooloose decompose the statusline long line warning function
authored
131 "return '[#x,my,$z] if long lines are found, were x is the number of long
132 "lines, y is the median length of the long lines and z is the length of the
133 "longest line
0596fef @scrooloose add a statusline warning if long lines are detected
authored
134 function! StatuslineLongLineWarning()
135 if !exists("b:statusline_long_line_warning")
b4ad446 @scrooloose supress statusbar warnings if the file is not modifiable
authored
136
137 if !&modifiable
138 let b:statusline_long_line_warning = ''
139 return b:statusline_long_line_warning
140 endif
141
d47587e @scrooloose decompose the statusline long line warning function
authored
142 let long_line_lens = s:LongLines()
0596fef @scrooloose add a statusline warning if long lines are detected
authored
143
e2ef6c8 @scrooloose make the long line warning more awesome
authored
144 if len(long_line_lens) > 0
d47587e @scrooloose decompose the statusline long line warning function
authored
145 let b:statusline_long_line_warning = "[" .
146 \ '#' . len(long_line_lens) . "," .
147 \ 'm' . s:Median(long_line_lens) . "," .
148 \ '$' . max(long_line_lens) . "]"
0596fef @scrooloose add a statusline warning if long lines are detected
authored
149 else
150 let b:statusline_long_line_warning = ""
151 endif
152 endif
153 return b:statusline_long_line_warning
154 endfunction
155
d47587e @scrooloose decompose the statusline long line warning function
authored
156 "return a list containing the lengths of the long lines in this buffer
157 function! s:LongLines()
158 let threshold = (&tw ? &tw : 80)
159 let spaces = repeat(" ", &ts)
160
161 let long_line_lens = []
162
163 let i = 1
164 while i <= line("$")
165 let len = strlen(substitute(getline(i), '\t', spaces, 'g'))
166 if len > threshold
167 call add(long_line_lens, len)
168 endif
169 let i += 1
170 endwhile
171
172 return long_line_lens
173 endfunction
174
e2ef6c8 @scrooloose make the long line warning more awesome
authored
175 "find the median of the given array of numbers
176 function! s:Median(nums)
177 let nums = sort(a:nums)
178 let l = len(nums)
179
180 if l % 2 == 1
181 let i = (l-1) / 2
182 return nums[i]
183 else
184 return (nums[l/2] + nums[(l/2)-1]) / 2
185 endif
186 endfunction
187
3cc6832 @scrooloose make vimrc compatible with vim 7.2 again
authored
188 if v:version >= 703
189 "undo settings
190 set undodir=~/.vim/undofiles
191 set undofile
b0c182a @scrooloose add persistent undo settings
authored
192
3cc6832 @scrooloose make vimrc compatible with vim 7.2 again
authored
193 set colorcolumn=+1
194 endif
5c87edf @scrooloose add colorcolumn setting
authored
195
63af46f @scrooloose add the useful parts of my vimrc
authored
196 "indent settings
197 set shiftwidth=4
198 set softtabstop=4
199 set expandtab
200 set autoindent
201
202 "folding settings
203 set foldmethod=indent "fold based on indent
204 set foldnestmax=3 "deepest fold is 3 levels
205 set nofoldenable "dont fold by default
206
207 set wildmode=list:longest "make cmdline tab completion similar to bash
208 set wildmenu "enable ctrl-n and ctrl-p to scroll thru matches
a695102 @scrooloose set wildignore
authored
209 set wildignore=*.o,*.obj,*~ "stuff to ignore when tab completing
63af46f @scrooloose add the useful parts of my vimrc
authored
210
211 "display tabs and trailing spaces
212 set list
213 set listchars=tab:▷⋅,trail:⋅,nbsp:⋅
214
215 set formatoptions-=o "dont continue comments when pushing o/O
216
217 "vertical/horizontal scroll off settings
218 set scrolloff=3
219 set sidescrolloff=7
220 set sidescroll=1
221
222 "load ftplugins and indent files
223 filetype plugin on
224 filetype indent on
225
226 "turn on syntax highlighting
227 syntax on
228
229 "some stuff to get the mouse going in term
230 set mouse=a
231 set ttymouse=xterm2
232
233 "tell the term has 256 colors
234 set t_Co=256
235
236 "hide buffers when not displayed
237 set hidden
238
332c677 @scrooloose dont source csapprox if we dont have gui support
authored
239 "dont load csapprox if we no gui support - silences an annoying warning
240 if !has("gui")
241 let g:CSApprox_loaded = 1
242 endif
243
63af46f @scrooloose add the useful parts of my vimrc
authored
244 "make <c-l> clear the highlight as well as redraw
245 nnoremap <C-L> :nohls<CR><C-L>
246 inoremap <C-L> <C-O>:nohls<CR>
247
6c1c2ae @scrooloose add map to buf explorer
authored
248 "map to bufexplorer
249 nnoremap <C-B> :BufExplorer<cr>
250
28dcbf3 @scrooloose add fuzzyfinder textmate style mod
authored
251 "map to fuzzy finder text mate stylez
252 nnoremap <c-f> :FuzzyFinderTextMate<CR>
253
63af46f @scrooloose add the useful parts of my vimrc
authored
254 "map Q to something useful
255 noremap Q gq
256
257 "make Y consistent with C and D
258 nnoremap Y y$
259
8e239bc @scrooloose enable syntastic signs by default
authored
260 "mark syntax errors with :signs
261 let g:syntastic_enable_signs=1
262
d903f14 @scrooloose add snipmate setup to vimrc
authored
263 "snipmate setup
264 source ~/.vim/snippets/support_functions.vim
9f7314c @scrooloose only load rails snippets if vim starts in a rails env
authored
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
d903f14 @scrooloose add snipmate setup to vimrc
authored
278
63af46f @scrooloose add the useful parts of my vimrc
authored
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
f170376 @scrooloose add some more to the vimrc
authored
290 "jump to last cursor position when opening a file
291 "dont do it when writing a commit log entry
63af46f @scrooloose add the useful parts of my vimrc
authored
292 autocmd BufReadPost * call SetCursorPosition()
293 function! SetCursorPosition()
08b6a53 @scrooloose dont change the cursor position for svn files
authored
294 if &filetype !~ 'svn\|commit\c'
63af46f @scrooloose add the useful parts of my vimrc
authored
295 if line("'\"") > 0 && line("'\"") <= line("$")
f5bd12f @scrooloose use normal! and center screen when restoring cursor position
authored
296 exe "normal! g`\""
297 normal! zz
63af46f @scrooloose add the useful parts of my vimrc
authored
298 endif
299 end
300 endfunction
301
b7420f5 @scrooloose enable spell check when writing commit logs
authored
302 "spell check when writing commit logs
303 autocmd filetype svn,*commit* set spell
304
56c3bbc @scrooloose rename HighlightExcessColums->HighlightLongLines and clean it up a bit
authored
305 "define :HighlightLongLines command to highlight the offending parts of
306 "lines that are longer than the specified length (defaulting to 80)
307 command! -nargs=? HighlightLongLines call s:HighlightLongLines('<args>')
308 function! s:HighlightLongLines(width)
309 let targetWidth = a:width != '' ? a:width : 79
f170376 @scrooloose add some more to the vimrc
authored
310 if targetWidth > 0
56c3bbc @scrooloose rename HighlightExcessColums->HighlightLongLines and clean it up a bit
authored
311 exec 'match Todo /\%>' . (targetWidth) . 'v/'
f170376 @scrooloose add some more to the vimrc
authored
312 else
56c3bbc @scrooloose rename HighlightExcessColums->HighlightLongLines and clean it up a bit
authored
313 echomsg "Usage: HighlightLongLines [natural number]"
f170376 @scrooloose add some more to the vimrc
authored
314 endif
315 endfunction
Something went wrong with that request. Please try again.