Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 280 lines (225 sloc) 8.241 kb
63af46f3 »
2008-09-21 add the useful parts of my vimrc
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 »
2008-11-30 display full path on statusline
21 set statusline=%f "tail of the filename
9e25fad6 »
2009-02-01 only show &ff and &fenc if they arent unix/utf-8
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 »
2009-02-02 dont show empty brackets when theres no &fenc
30 set statusline+=%{(&fenc!='utf-8'&&&fenc!='')?'['.&fenc.']':''}
9e25fad6 »
2009-02-01 only show &ff and &fenc if they arent unix/utf-8
31 set statusline+=%*
32
63af46f3 »
2008-09-21 add the useful parts of my vimrc
33 set statusline+=%h "help file flag
34 set statusline+=%y "filetype
26a67929 »
2008-10-29 make the statusline own harder
35 set statusline+=%r "read only flag
36 set statusline+=%m "modified flag
03cf502e »
2008-10-28 make the statusline own harder
37
9f5a0fdc »
2008-10-29 maket the tab warning on the stl own more
38 "display a warning if &et is wrong, or we have mixed-indenting
03cf502e »
2008-10-28 make the statusline own harder
39 set statusline+=%#error#
40 set statusline+=%{StatuslineTabWarning()}
41 set statusline+=%*
42
26a67929 »
2008-10-29 make the statusline own harder
43 set statusline+=%{StatuslineTrailingSpaceWarning()}
07d5ca1e »
2008-11-19 error highlight display the [paste] flag
44
0596fefb »
2009-06-18 add a statusline warning if long lines are detected
45 set statusline+=%{StatuslineLongLineWarning()}
46
07d5ca1e »
2008-11-19 error highlight display the [paste] flag
47 "display a warning if &paste is set
48 set statusline+=%#error#
49 set statusline+=%{&paste?'[paste]':''}
50 set statusline+=%*
51
63af46f3 »
2008-09-21 add the useful parts of my vimrc
52 set statusline+=%= "left/right separator
26a67929 »
2008-10-29 make the statusline own harder
53 set statusline+=%{StatuslineCurrentHighlight()}\ \ "current highlight
63af46f3 »
2008-09-21 add the useful parts of my vimrc
54 set statusline+=%c, "cursor column
55 set statusline+=%l/%L "cursor line/total lines
56 set statusline+=\ %P "percent through file
57 set laststatus=2
58
26a67929 »
2008-10-29 make the statusline own harder
59 "recalculate the trailing whitespace warning when idle, and after saving
60 autocmd cursorhold,bufwritepost * unlet! b:statusline_trailing_space_warning
61
62 "return '[\s]' if trailing white space is detected
63 "return '' otherwise
64 function! StatuslineTrailingSpaceWarning()
65 if !exists("b:statusline_trailing_space_warning")
66 if search('\s\+$', 'nw') != 0
67 let b:statusline_trailing_space_warning = '[\s]'
68 else
69 let b:statusline_trailing_space_warning = ''
70 endif
71 endif
72 return b:statusline_trailing_space_warning
73 endfunction
74
75
76 "return the syntax highlight group under the cursor ''
ce89cd03 »
2008-10-08 add hilight group under cursor to statusline
77 function! StatuslineCurrentHighlight()
78 let name = synIDattr(synID(line('.'),col('.'),1),'name')
26a67929 »
2008-10-29 make the statusline own harder
79 if name == ''
80 return ''
81 else
82 return '[' . name . ']'
ce89cd03 »
2008-10-08 add hilight group under cursor to statusline
83 endif
84 endfunction
85
9f5a0fdc »
2008-10-29 maket the tab warning on the stl own more
86 "recalculate the tab warning flag when idle and after writing
87 autocmd cursorhold,bufwritepost * unlet! b:statusline_tab_warning
88
89 "return '[&et]' if &et is set wrong
90 "return '[mixed-indenting]' if spaces and tabs are used to indent
91 "return an empty string if everything is fine
03cf502e »
2008-10-28 make the statusline own harder
92 function! StatuslineTabWarning()
9f5a0fdc »
2008-10-29 maket the tab warning on the stl own more
93 if !exists("b:statusline_tab_warning")
d2bd0034 »
2008-11-02 update statusline hax
94 let tabs = search('^\t', 'nw') != 0
95 let spaces = search('^ ', 'nw') != 0
9f5a0fdc »
2008-10-29 maket the tab warning on the stl own more
96
97 if tabs && spaces
98 let b:statusline_tab_warning = '[mixed-indenting]'
99 elseif (spaces && !&et) || (tabs && &et)
100 let b:statusline_tab_warning = '[&et]'
101 else
102 let b:statusline_tab_warning = ''
103 endif
03cf502e »
2008-10-28 make the statusline own harder
104 endif
9f5a0fdc »
2008-10-29 maket the tab warning on the stl own more
105 return b:statusline_tab_warning
03cf502e »
2008-10-28 make the statusline own harder
106 endfunction
107
0596fefb »
2009-06-18 add a statusline warning if long lines are detected
108 "recalculate the long line warning when idle and after saving
109 autocmd cursorhold,bufwritepost * unlet! b:statusline_long_line_warning
110
dcfd9218 »
2009-06-26 bugfix and awesomify the long line warning
111 "return a warning for "long lines" where "long" is either &textwidth or 80 (if
112 "no &textwidth is set)
113 "
114 "return '' if no long lines
e2ef6c82 »
2009-06-28 make the long line warning more awesome
115 "return '[#x,my,$z] if multiple long lines are found, were x is the number of
116 "long lines, y is the median length of the long lines and z is the length of
117 "the longest line
118 "return '[$x]' if one long line is found, where x is the length of the line
0596fefb »
2009-06-18 add a statusline warning if long lines are detected
119 function! StatuslineLongLineWarning()
120 if !exists("b:statusline_long_line_warning")
dcfd9218 »
2009-06-26 bugfix and awesomify the long line warning
121 let threshold = (&tw ? &tw : 80)
122 let spaces = repeat(" ", 8)
0596fefb »
2009-06-18 add a statusline warning if long lines are detected
123
e2ef6c82 »
2009-06-28 make the long line warning more awesome
124 let long_line_lens = []
dcfd9218 »
2009-06-26 bugfix and awesomify the long line warning
125
126 let i = 1
127 while i <= line("$")
128 let len = strlen(substitute(getline(i), '\t', spaces, 'g'))
129 if len > threshold
e2ef6c82 »
2009-06-28 make the long line warning more awesome
130 call add(long_line_lens, len)
0596fefb »
2009-06-18 add a statusline warning if long lines are detected
131 endif
dcfd9218 »
2009-06-26 bugfix and awesomify the long line warning
132 let i += 1
0596fefb »
2009-06-18 add a statusline warning if long lines are detected
133 endwhile
134
e2ef6c82 »
2009-06-28 make the long line warning more awesome
135 if len(long_line_lens) > 0
136 let b:statusline_long_line_warning = "["
137
138 if len(long_line_lens) > 1
139 let b:statusline_long_line_warning .=
140 \ '#' . len(long_line_lens) . "," .
141 \ 'm' . s:Median(long_line_lens) . ","
142 endif
143
144 let b:statusline_long_line_warning .= '$' .
145 \ max(long_line_lens) . "]"
0596fefb »
2009-06-18 add a statusline warning if long lines are detected
146 else
147 let b:statusline_long_line_warning = ""
148 endif
149 endif
150 return b:statusline_long_line_warning
151 endfunction
152
e2ef6c82 »
2009-06-28 make the long line warning more awesome
153 "find the median of the given array of numbers
154 function! s:Median(nums)
155 let nums = sort(a:nums)
156 let l = len(nums)
157
158 if l % 2 == 1
159 let i = (l-1) / 2
160 return nums[i]
161 else
162 return (nums[l/2] + nums[(l/2)-1]) / 2
163 endif
164 endfunction
165
63af46f3 »
2008-09-21 add the useful parts of my vimrc
166 "indent settings
167 set shiftwidth=4
168 set softtabstop=4
169 set expandtab
170 set autoindent
171
172 "folding settings
173 set foldmethod=indent "fold based on indent
174 set foldnestmax=3 "deepest fold is 3 levels
175 set nofoldenable "dont fold by default
176
177 set wildmode=list:longest "make cmdline tab completion similar to bash
178 set wildmenu "enable ctrl-n and ctrl-p to scroll thru matches
a695102a »
2008-10-30 set wildignore
179 set wildignore=*.o,*.obj,*~ "stuff to ignore when tab completing
63af46f3 »
2008-09-21 add the useful parts of my vimrc
180
181 "display tabs and trailing spaces
182 set list
183 set listchars=tab:▷⋅,trail:⋅,nbsp:⋅
184
185 set formatoptions-=o "dont continue comments when pushing o/O
186
187 "vertical/horizontal scroll off settings
188 set scrolloff=3
189 set sidescrolloff=7
190 set sidescroll=1
191
192 "load ftplugins and indent files
193 filetype plugin on
194 filetype indent on
195
196 "turn on syntax highlighting
197 syntax on
198
199 "some stuff to get the mouse going in term
200 set mouse=a
201 set ttymouse=xterm2
202
203 "tell the term has 256 colors
204 set t_Co=256
205
206 "hide buffers when not displayed
207 set hidden
208
332c6778 »
2008-10-07 dont source csapprox if we dont have gui support
209 "dont load csapprox if we no gui support - silences an annoying warning
210 if !has("gui")
211 let g:CSApprox_loaded = 1
212 endif
213
63af46f3 »
2008-09-21 add the useful parts of my vimrc
214 "make <c-l> clear the highlight as well as redraw
215 nnoremap <C-L> :nohls<CR><C-L>
216 inoremap <C-L> <C-O>:nohls<CR>
217
6c1c2aef »
2008-10-12 add map to buf explorer
218 "map to bufexplorer
219 nnoremap <C-B> :BufExplorer<cr>
220
28dcbf31 »
2008-10-19 add fuzzyfinder textmate style mod
221 "map to fuzzy finder text mate stylez
222 nnoremap <c-f> :FuzzyFinderTextMate<CR>
223
63af46f3 »
2008-09-21 add the useful parts of my vimrc
224 "map Q to something useful
225 noremap Q gq
226
227 "make Y consistent with C and D
228 nnoremap Y y$
229
d903f144 »
2009-06-07 add snipmate setup to vimrc
230 "snipmate setup
231 source ~/.vim/snippets/support_functions.vim
9f7314c5 »
2009-06-18 only load rails snippets if vim starts in a rails env
232 autocmd vimenter * call s:SetupSnippets()
233 function! s:SetupSnippets()
234
235 "if we're in a rails env then read in the rails snippets
236 if filereadable("./config/environment.rb")
237 call ExtractSnips("~/.vim/snippets/ruby-rails", "ruby")
238 call ExtractSnips("~/.vim/snippets/eruby-rails", "eruby")
239 endif
240
241 call ExtractSnips("~/.vim/snippets/html", "eruby")
242 call ExtractSnips("~/.vim/snippets/html", "xhtml")
243 call ExtractSnips("~/.vim/snippets/html", "php")
244 endfunction
d903f144 »
2009-06-07 add snipmate setup to vimrc
245
63af46f3 »
2008-09-21 add the useful parts of my vimrc
246 "visual search mappings
247 function! s:VSetSearch()
248 let temp = @@
249 norm! gvy
250 let @/ = '\V' . substitute(escape(@@, '\'), '\n', '\\n', 'g')
251 let @@ = temp
252 endfunction
253 vnoremap * :<C-u>call <SID>VSetSearch()<CR>//<CR>
254 vnoremap # :<C-u>call <SID>VSetSearch()<CR>??<CR>
255
256
f170376c »
2008-09-23 add some more to the vimrc
257 "jump to last cursor position when opening a file
258 "dont do it when writing a commit log entry
63af46f3 »
2008-09-21 add the useful parts of my vimrc
259 autocmd BufReadPost * call SetCursorPosition()
260 function! SetCursorPosition()
261 if &filetype !~ 'commit\c'
262 if line("'\"") > 0 && line("'\"") <= line("$")
f5bd12f3 »
2009-06-08 use normal! and center screen when restoring cursor position
263 exe "normal! g`\""
264 normal! zz
63af46f3 »
2008-09-21 add the useful parts of my vimrc
265 endif
266 end
267 endfunction
268
56c3bbcb »
2009-06-18 rename HighlightExcessColums->HighlightLongLines and clean it up a bit
269 "define :HighlightLongLines command to highlight the offending parts of
270 "lines that are longer than the specified length (defaulting to 80)
271 command! -nargs=? HighlightLongLines call s:HighlightLongLines('<args>')
272 function! s:HighlightLongLines(width)
273 let targetWidth = a:width != '' ? a:width : 79
f170376c »
2008-09-23 add some more to the vimrc
274 if targetWidth > 0
56c3bbcb »
2009-06-18 rename HighlightExcessColums->HighlightLongLines and clean it up a bit
275 exec 'match Todo /\%>' . (targetWidth) . 'v/'
f170376c »
2008-09-23 add some more to the vimrc
276 else
56c3bbcb »
2009-06-18 rename HighlightExcessColums->HighlightLongLines and clean it up a bit
277 echomsg "Usage: HighlightLongLines [natural number]"
f170376c »
2008-09-23 add some more to the vimrc
278 endif
279 endfunction
Something went wrong with that request. Please try again.