Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 314 lines (248 sloc) 8.971 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
111 let spaces = search('^ ', 'nw') != 0
9f5a0fd @scrooloose maket the tab warning on the stl own more
authored
112
3ae194e @scrooloose upgrade the statsline indent warning
authored
113
9f5a0fd @scrooloose maket the tab warning on the stl own more
authored
114 if tabs && spaces
3ae194e @scrooloose upgrade the statsline indent warning
authored
115
116 if &et
117 let b:statusline_tab_warning = '[mixed-indenting]'
118 else
119 "if using tabs, allow alignment at the start of the line
120 "of up to one &ts width
121 if search('^ \{' . &ts . ',}', 'nw') != 0
122 let b:statusline_tab_warning = '[mixed-indenting]'
123 endif
124 endif
125
9f5a0fd @scrooloose maket the tab warning on the stl own more
authored
126 elseif (spaces && !&et) || (tabs && &et)
127 let b:statusline_tab_warning = '[&et]'
128 endif
03cf502 @scrooloose make the statusline own harder
authored
129 endif
9f5a0fd @scrooloose maket the tab warning on the stl own more
authored
130 return b:statusline_tab_warning
03cf502 @scrooloose make the statusline own harder
authored
131 endfunction
132
0596fef @scrooloose add a statusline warning if long lines are detected
authored
133 "recalculate the long line warning when idle and after saving
134 autocmd cursorhold,bufwritepost * unlet! b:statusline_long_line_warning
135
dcfd921 @scrooloose bugfix and awesomify the long line warning
authored
136 "return a warning for "long lines" where "long" is either &textwidth or 80 (if
137 "no &textwidth is set)
138 "
139 "return '' if no long lines
d47587e @scrooloose decompose the statusline long line warning function
authored
140 "return '[#x,my,$z] if long lines are found, were x is the number of long
141 "lines, y is the median length of the long lines and z is the length of the
142 "longest line
0596fef @scrooloose add a statusline warning if long lines are detected
authored
143 function! StatuslineLongLineWarning()
144 if !exists("b:statusline_long_line_warning")
b4ad446 @scrooloose supress statusbar warnings if the file is not modifiable
authored
145
146 if !&modifiable
147 let b:statusline_long_line_warning = ''
148 return b:statusline_long_line_warning
149 endif
150
d47587e @scrooloose decompose the statusline long line warning function
authored
151 let long_line_lens = s:LongLines()
0596fef @scrooloose add a statusline warning if long lines are detected
authored
152
e2ef6c8 @scrooloose make the long line warning more awesome
authored
153 if len(long_line_lens) > 0
d47587e @scrooloose decompose the statusline long line warning function
authored
154 let b:statusline_long_line_warning = "[" .
155 \ '#' . len(long_line_lens) . "," .
156 \ 'm' . s:Median(long_line_lens) . "," .
157 \ '$' . max(long_line_lens) . "]"
0596fef @scrooloose add a statusline warning if long lines are detected
authored
158 else
159 let b:statusline_long_line_warning = ""
160 endif
161 endif
162 return b:statusline_long_line_warning
163 endfunction
164
d47587e @scrooloose decompose the statusline long line warning function
authored
165 "return a list containing the lengths of the long lines in this buffer
166 function! s:LongLines()
167 let threshold = (&tw ? &tw : 80)
168 let spaces = repeat(" ", &ts)
169
170 let long_line_lens = []
171
172 let i = 1
173 while i <= line("$")
174 let len = strlen(substitute(getline(i), '\t', spaces, 'g'))
175 if len > threshold
176 call add(long_line_lens, len)
177 endif
178 let i += 1
179 endwhile
180
181 return long_line_lens
182 endfunction
183
e2ef6c8 @scrooloose make the long line warning more awesome
authored
184 "find the median of the given array of numbers
185 function! s:Median(nums)
186 let nums = sort(a:nums)
187 let l = len(nums)
188
189 if l % 2 == 1
190 let i = (l-1) / 2
191 return nums[i]
192 else
193 return (nums[l/2] + nums[(l/2)-1]) / 2
194 endif
195 endfunction
196
63af46f @scrooloose add the useful parts of my vimrc
authored
197 "indent settings
198 set shiftwidth=4
199 set softtabstop=4
200 set expandtab
201 set autoindent
202
203 "folding settings
204 set foldmethod=indent "fold based on indent
205 set foldnestmax=3 "deepest fold is 3 levels
206 set nofoldenable "dont fold by default
207
208 set wildmode=list:longest "make cmdline tab completion similar to bash
209 set wildmenu "enable ctrl-n and ctrl-p to scroll thru matches
a695102 @scrooloose set wildignore
authored
210 set wildignore=*.o,*.obj,*~ "stuff to ignore when tab completing
63af46f @scrooloose add the useful parts of my vimrc
authored
211
212 "display tabs and trailing spaces
213 set list
214 set listchars=tab:▷⋅,trail:⋅,nbsp:⋅
215
216 set formatoptions-=o "dont continue comments when pushing o/O
217
218 "vertical/horizontal scroll off settings
219 set scrolloff=3
220 set sidescrolloff=7
221 set sidescroll=1
222
223 "load ftplugins and indent files
224 filetype plugin on
225 filetype indent on
226
227 "turn on syntax highlighting
228 syntax on
229
230 "some stuff to get the mouse going in term
231 set mouse=a
232 set ttymouse=xterm2
233
234 "tell the term has 256 colors
235 set t_Co=256
236
237 "hide buffers when not displayed
238 set hidden
239
332c677 @scrooloose dont source csapprox if we dont have gui support
authored
240 "dont load csapprox if we no gui support - silences an annoying warning
241 if !has("gui")
242 let g:CSApprox_loaded = 1
243 endif
244
63af46f @scrooloose add the useful parts of my vimrc
authored
245 "make <c-l> clear the highlight as well as redraw
246 nnoremap <C-L> :nohls<CR><C-L>
247 inoremap <C-L> <C-O>:nohls<CR>
248
6c1c2ae @scrooloose add map to buf explorer
authored
249 "map to bufexplorer
250 nnoremap <C-B> :BufExplorer<cr>
251
28dcbf3 @scrooloose add fuzzyfinder textmate style mod
authored
252 "map to fuzzy finder text mate stylez
253 nnoremap <c-f> :FuzzyFinderTextMate<CR>
254
63af46f @scrooloose add the useful parts of my vimrc
authored
255 "map Q to something useful
256 noremap Q gq
257
258 "make Y consistent with C and D
259 nnoremap Y y$
260
8e239bc @scrooloose enable syntastic signs by default
authored
261 "mark syntax errors with :signs
262 let g:syntastic_enable_signs=1
263
d903f14 @scrooloose add snipmate setup to vimrc
authored
264 "snipmate setup
265 source ~/.vim/snippets/support_functions.vim
9f7314c @scrooloose only load rails snippets if vim starts in a rails env
authored
266 autocmd vimenter * call s:SetupSnippets()
267 function! s:SetupSnippets()
268
269 "if we're in a rails env then read in the rails snippets
270 if filereadable("./config/environment.rb")
271 call ExtractSnips("~/.vim/snippets/ruby-rails", "ruby")
272 call ExtractSnips("~/.vim/snippets/eruby-rails", "eruby")
273 endif
274
275 call ExtractSnips("~/.vim/snippets/html", "eruby")
276 call ExtractSnips("~/.vim/snippets/html", "xhtml")
277 call ExtractSnips("~/.vim/snippets/html", "php")
278 endfunction
d903f14 @scrooloose add snipmate setup to vimrc
authored
279
63af46f @scrooloose add the useful parts of my vimrc
authored
280 "visual search mappings
281 function! s:VSetSearch()
282 let temp = @@
283 norm! gvy
284 let @/ = '\V' . substitute(escape(@@, '\'), '\n', '\\n', 'g')
285 let @@ = temp
286 endfunction
287 vnoremap * :<C-u>call <SID>VSetSearch()<CR>//<CR>
288 vnoremap # :<C-u>call <SID>VSetSearch()<CR>??<CR>
289
290
f170376 @scrooloose add some more to the vimrc
authored
291 "jump to last cursor position when opening a file
292 "dont do it when writing a commit log entry
63af46f @scrooloose add the useful parts of my vimrc
authored
293 autocmd BufReadPost * call SetCursorPosition()
294 function! SetCursorPosition()
295 if &filetype !~ 'commit\c'
296 if line("'\"") > 0 && line("'\"") <= line("$")
f5bd12f @scrooloose use normal! and center screen when restoring cursor position
authored
297 exe "normal! g`\""
298 normal! zz
63af46f @scrooloose add the useful parts of my vimrc
authored
299 endif
300 end
301 endfunction
302
56c3bbc @scrooloose rename HighlightExcessColums->HighlightLongLines and clean it up a bit
authored
303 "define :HighlightLongLines command to highlight the offending parts of
304 "lines that are longer than the specified length (defaulting to 80)
305 command! -nargs=? HighlightLongLines call s:HighlightLongLines('<args>')
306 function! s:HighlightLongLines(width)
307 let targetWidth = a:width != '' ? a:width : 79
f170376 @scrooloose add some more to the vimrc
authored
308 if targetWidth > 0
56c3bbc @scrooloose rename HighlightExcessColums->HighlightLongLines and clean it up a bit
authored
309 exec 'match Todo /\%>' . (targetWidth) . 'v/'
f170376 @scrooloose add some more to the vimrc
authored
310 else
56c3bbc @scrooloose rename HighlightExcessColums->HighlightLongLines and clean it up a bit
authored
311 echomsg "Usage: HighlightLongLines [natural number]"
f170376 @scrooloose add some more to the vimrc
authored
312 endif
313 endfunction
Something went wrong with that request. Please try again.