summaryrefslogtreecommitdiff
path: root/.vimrc
diff options
context:
space:
mode:
authorMike Crute <mcrute@gmail.com>2009-09-27 15:23:25 -0400
committerMike Crute <mcrute@gmail.com>2009-09-27 15:23:25 -0400
commit2df938762c697ca9eeab3329dacd8f2ca8151359 (patch)
treeee11dfd34eeb5796fe322ca3c121c39179f10045 /.vimrc
downloaddotfiles-2df938762c697ca9eeab3329dacd8f2ca8151359.tar.bz2
dotfiles-2df938762c697ca9eeab3329dacd8f2ca8151359.tar.xz
dotfiles-2df938762c697ca9eeab3329dacd8f2ca8151359.zip
Initial checkin of dotfiles.
Diffstat (limited to '.vimrc')
-rw-r--r--.vimrc632
1 files changed, 632 insertions, 0 deletions
diff --git a/.vimrc b/.vimrc
new file mode 100644
index 0000000..4c9abab
--- /dev/null
+++ b/.vimrc
@@ -0,0 +1,632 @@
1
2"
3" .vimrc VIM Preferences File
4" by Mike Crute (mcrute@gmail.com)
5"
6
7" The author_info.vim file defines the global used in the template
8" support functions. This will vary based on the computer where
9" vim is being used (work vs home, etc...) so it makes sense to
10" keep it seperate.
11source ~/.vim/author_info.vim
12
13" Syntax Highlighting {{{
14syntax on
15colorscheme mcrute_slate
16set background=dark
17
18" MacVim gets its transparency settings all horked up if we don't
19" set this before we do GUI initialization stuff.
20set nocompatible
21
22" Have to do something a little different on the GUI otherwise its
23" totally impossible to see what we're doing. The cols/lines fits
24" pretty nicely on a 15" MBP at highest resolution.
25if has("gui_macvim") && has("gui_running")
26 set transparency=8
27 colorscheme mcrute
28 "set lines=65
29 "set columns=230
30 " This size feels nice, to too big, not too small
31 set columns=100
32 set lines=53
33 set guifont=Monaco:h10.00
34 set go-=T
35endif
36
37" Monospace 8 is a pretty nice font if we're running under GVIM.
38" The columns/lines in this setting fits just perfectly on my
39" Linux desktop at work at hightest resolution.
40if has("gui_gtk") && has("gui_running")
41 "set lines=75
42 "set columns=238
43 " This size feels nice, to too big, not too small
44 set columns=100
45 set lines=53
46 set guifont=Monospace\ 8
47 set guioptions=aegimrLt
48endif
49" }}}
50" General Settings {{{
51set backspace=indent,eol,start
52set browsedir=buffer
53set fileformat=unix
54set hidden
55set history=1000
56set modeline
57set title
58set nojoinspaces
59set backup
60set directory=~/.vim/tmp,~/.tmp,~/tmp,/var/tmp,/tmp
61set backupdir=~/.vim/tmp,~/.tmp,~/tmp,/var/tmp,/tmp
62" }}}
63" Search Settings {{{
64set hlsearch
65set incsearch
66set showmatch
67set ignorecase
68set smartcase
69" }}}
70" Tab Settings {{{
71set autoindent
72set expandtab
73set shiftwidth=4
74"set smartindent " Screws up python indenting
75set smarttab
76set softtabstop=4
77set tabstop=4
78" }}}
79" Visual Display {{{
80set laststatus=2
81"set list
82set noequalalways
83set nowrap
84set number
85set ruler
86set scrolloff=4
87set showcmd
88set showtabline=2
89set splitbelow
90set splitright
91set virtualedit=all
92set wildmenu
93
94" Some stuff isn't availiable in < 7.0
95if version >= 700
96 set nospell
97endif
98" }}}
99" Vim Plugins {{{
100filetype plugin on
101filetype indent on
102
103" Use verital splits for file explorer
104let g:explVertical=1
105" }}}
106" File Type -> Highlighting Maps {{{
107" AGI PD Template Files
108autocmd BufNewFile,BufRead,BufReadPost *.pd
109 \ set syntax=pyfusion
110
111" Apache Files in Apache dirs
112autocmd BufNewFile,BufRead,BufReadPost /*apache*
113 \ set syntax=apache
114
115" Python Files
116autocmd BufNewFile,BufRead *.py
117 \ setlocal foldmarker=#{,#}
118" }}}
119" Custom Commands {{{
120" Cleanup windows crap from line endings
121command FixLineEnd %s/ //gi
122command PEP8 call IsPEP8()
123" }}}
124" Key Bindings {{{
125set pastetoggle=<F12>
126
127" Tab Key Bindings
128map nt :tabnew<CR>
129map tm :tabmove<CR>
130map tn :tabnext<CR>
131map tp :tabprev<CR>
132map tc :tabclose<CR>
133
134" Buffer Key Bindings
135map <C-l> :bnext!<CR>
136map <C-h> :bprev!<CR>
137map bn :bnext<CR>
138map bp :bprev<CR>
139
140" Paging Key Bindings
141map df <C-f>
142map fd <C-b>
143
144" Plugin Key Bindings
145map <unique> <leader>tl :TlistToggle<CR>
146map <unique> <leader>fe :Vexplore<CR>
147
148nmap \ih :call InsertTemplate("header", 1)<CR>
149map <silent><F6> :call SVNDiff()<CR>
150
151" Convenience Key Bindings
152" cs: clears search buffer
153map cs :let @/=""<CR>
154map sp :set spell!<CR>
155map txt :set filetype=text<CR>
156
157" GUI-style Saving!
158map <C-s> :w<CR>
159
160" Turns selected camelCase into camel_case
161vnoremap ,dc :s/\v\C(([a-z]+)([A-Z]))/\2_\l\3/g<CR>
162" }}}
163" Folding Settings {{{
164set foldenable
165set foldcolumn=3
166set foldmethod=marker
167" }}}
168" Striving for Python Zen {{{
169let python_highlight_all=1
170
171" Code completion!
172autocmd FileType python set omnifunc=pythoncomplete#Complete
173inoremap <Nul> <C-x><C-o>
174
175" Remove trailing spaces from *.py files for PEP8 compliance
176function! TrimSpaces()
177 :%s/\s\+$//e
178endfunction
179
180"autocmd BufWritePre *.py call TrimSpaces
181
182" Run pep8 checks if we can
183function! IsPEP8()
184 if executable("agi-pep8.py")
185 !agi-pep8.py %
186 endif
187endfunction
188
189" Run pylint on the file
190if executable("pylint")
191" autocmd BufWritePost *.py !pylint -rn %
192" autocmd BufRead *.py set makeprg=pylint\ -rn\ %
193elseif executable("agi-pep8.py")
194" autocmd BufWritePost *.py !agi-pep8.py %
195" autocmd BufRead *.py set makeprg=agi-pep8.py\ %
196endif
197
198" Allow us to gf into import statements
199if has("python")
200python << EOF
201import os, sys, vim
202for p in sys.path:
203 if os.path.isdir(p):
204 vim.command(r"set path+=%s" % (p.replace(" ", r"\ ")))
205EOF
206endif
207" }}}
208" Automatic Commands {{{
209"autocmd BufWinLeave * silent! mkview
210"autocmd BufWinEnter * silent! loadview
211"autocmd FileType python compiler nose
212" }}}
213" Line and Column Highlighting {{{
214autocmd BufEnter * call SetColumnHighlighting(1)
215autocmd BufLeave * call SetColumnHighlighting(0)
216
217function! SetColumnHighlighting(set_on)
218 if $TERM_PROGRAM == "Apple_Terminal" || version < 700
219 " Apple's Terminal.app is more than slightly retarded when it comes
220 " to colors and term compatibility so don't do this stuff on a Mac.
221 return
222 endif
223
224 if (!&readonly && a:set_on) && &filetype != "text"
225 set cursorline
226 set cursorcolumn
227
228 autocmd BufEnter * hi CursorLine term=none cterm=none ctermbg=0
229 autocmd BufEnter * hi CursorLine term=none cterm=none ctermbg=0
230
231 " Sets a dark grey background on the current line in 8-bit terminals
232 " sadly, this does not have any effect on the Mac OS X terminal.
233 hi CursorLine term=none cterm=none ctermbg=0
234 else
235 set nocursorline
236 set nocursorcolumn
237 endif
238endfunction
239" }}}
240" Text Mode File Support {{{
241autocmd FileType text call DoTextMode()
242
243function! DoTextMode()
244 set textwidth=80
245 set nolist
246 set spell
247 call SetColumnHighlighting(0)
248endfunction
249" }}}
250" Invisibles Display {{{
251function! Cream_listchars_init()
252 set listchars=
253
254 " tab
255 if v:version < 603
256 " greaterthan, followed by space
257 execute "set listchars+=tab:" . nr2char(62) . '\ '
258 elseif strlen(substitute(strtrans(nr2char(187)), ".", "x", "g")) == 1
259 " right angle quote, guillemotright followed by space (digraph >>)
260 execute "set listchars+=tab:" . nr2char(187) . '\ '
261 else
262 " greaterthan, followed by space
263 execute "set listchars+=tab:" . nr2char(62) . '\ '
264 endif
265
266 " eol
267 if v:version < 603
268 " dollar sign
269 execute "set listchars+=eol:" . nr2char(36)
270 elseif strlen(substitute(strtrans(nr2char(182)), ".", "x", "g")) == 1
271 " paragrah symbol (digraph PI)
272 execute "set listchars+=eol:" . nr2char(182)
273 else
274 " dollar sign
275 execute "set listchars+=eol:" . nr2char(36)
276 endif
277
278 " trail
279 if v:version < 603
280 " period
281 execute "set listchars+=trail:" . nr2char(46)
282 elseif strlen(substitute(strtrans(nr2char(183)), ".", "x", "g")) == 1
283 " others digraphs: 0U 0M/M0 sB .M 0m/m0 RO
284 " middle dot (digraph .M)
285 execute "set listchars+=trail:" . nr2char(183)
286 else
287 " period
288 execute "set listchars+=trail:" . nr2char(46)
289 endif
290
291 " precedes
292 if v:version < 603
293 " underscore
294 execute "set listchars+=precedes:" . nr2char(95)
295 elseif strlen(substitute(strtrans(nr2char(133)), ".", "x", "g")) == 1
296 " ellipses
297 execute "set listchars+=precedes:" . nr2char(133)
298 elseif strlen(substitute(strtrans(nr2char(8230)), ".", "x", "g")) == 1
299 " ellipses (2nd try)
300 execute "set listchars+=precedes:" . nr2char(8230)
301 elseif strlen(substitute(strtrans(nr2char(8249)), ".", "x", "g")) == 1
302 \&& v:lang != "C"
303 " mathematical lessthan (digraph <1)
304 execute "set listchars+=precedes:" . nr2char(8249)
305 elseif strlen(substitute(strtrans(nr2char(8592)), ".", "x", "g")) == 1
306 " left arrow (digraph <-)
307 execute "set listchars+=precedes:" . nr2char(8592)
308 else
309 " underscore
310 execute "set listchars+=precedes:" . nr2char(95)
311 endif
312
313 " extends
314 if v:version < 603
315 " underscore
316 execute "set listchars+=extends:" . nr2char(95)
317 elseif strlen(substitute(strtrans(nr2char(133)), ".", "x", "g")) == 1
318 " ellipses
319 execute "set listchars+=extends:" . nr2char(133)
320 elseif strlen(substitute(strtrans(nr2char(8230)), ".", "x", "g")) == 1
321 " ellipses (2nd try)
322 execute "set listchars+=extends:" . nr2char(8230)
323 elseif strlen(substitute(strtrans(nr2char(8250)), ".", "x", "g")) == 1
324 \&& v:lang != "C"
325 " mathematical greaterthan (digraph >1)
326 execute "set listchars+=extends:" . nr2char(8250)
327 elseif strlen(substitute(strtrans(nr2char(8594)), ".", "x", "g")) == 1
328 " right arrow (digraph ->)
329 execute "set listchars+=extends:" . nr2char(8594)
330 else
331 " underscore
332 execute "set listchars+=extends:" . nr2char(95)
333 endif
334
335endfunction
336call Cream_listchars_init()
337" }}}
338" Template Support {{{
339let s:Template_Directory = $HOME . '/.vim/templates/'
340
341function! SubstituteTag(pos1, pos2, tag, replacement)
342 let linenumber = a:pos1
343
344 while linenumber <= a:pos2
345 let line = getline(linenumber)
346 let start = 0
347
348 while match(line,a:tag,start) >= 0
349 let frst = match(line, a:tag, start)
350 let last = matchend(line, a:tag, start)
351
352 if frst !=- 1
353 let part1 = strpart(line, 0, frst)
354 let part2 = strpart(line, last)
355 let line = part1 . a:replacement.part2
356 let start = strlen(part1) + strlen(a:replacement)
357 endif
358 endwhile
359
360 call setline(linenumber, line)
361 let linenumber = linenumber + 1
362 endwhile
363endfunction
364
365function! InsertTemplate(template, header)
366 let templatefile = s:Template_Directory
367
368 if exists("b:current_syntax")
369 let templatefile = templatefile . b:current_syntax . '/' . a:template
370 else
371 let templatefile = templatefile . 'default/' . a:template
372 endif
373
374 if filereadable(templatefile)
375 let length = line("$")
376 let pos1 = line(".") + 1
377 let l:old_cpoptions = &cpoptions
378 setlocal cpoptions-=a
379
380 if a:header
381 :goto 1
382 let pos1 = 1
383 exe '0read ' . templatefile
384 else
385 exe 'read ' . templatefile
386 endif
387
388 let &cpoptions = l:old_cpoptions
389 let length = line("$") - length
390 let pos2 = pos1 + length - 1
391
392 call SubstituteTag(pos1, pos2, '|FILENAME|', expand("%:t"))
393 call SubstituteTag(pos1, pos2, '|DATE|', strftime('%x'))
394 call SubstituteTag(pos1, pos2, '|TEXTDATE|', strftime('%B %d, %Y'))
395 call SubstituteTag(pos1, pos2, '|DATETIME|', strftime('%x %X %Z'))
396 call SubstituteTag(pos1, pos2, '|TIME|', strftime('%X %Z'))
397 call SubstituteTag(pos1, pos2, '|YEAR|', strftime('%Y'))
398 call SubstituteTag(pos1, pos2, '|AUTHOR|', g:AuthorName)
399 call SubstituteTag(pos1, pos2, '|EMAIL|', g:Email)
400 call SubstituteTag(pos1, pos2, '|AUTHORREF|', g:AuthorRef)
401 call SubstituteTag(pos1, pos2, '|PROJECT|', g:Project)
402 call SubstituteTag(pos1, pos2, '|COMPANY|', g:Company)
403 call SubstituteTag(pos1, pos2, '|COPYRIGHTHOLDER|', g:CopyrightHolder)
404
405 exe ':' . pos1
406 normal 0
407
408 let linenumber = search('|CURSOR|')
409
410 if linenumber >= pos1 && linenumber <= pos2
411 let pos1 = match(getline(linenumber), "|CURSOR|")
412
413 if matchend(getline(linenumber), "|CURSOR|") == match(getline(linenumber), "$")
414 silent! s/|CURSOR|//
415 :startinsert!
416 else
417 silent s/|CURSOR|//
418 call cursor(linenumber, pos1 + 1)
419 :startinsert
420 endif
421 endif
422 else
423 echohl WarningMsg | echo 'template file '.templatefile.' does not exist or is not readable'| echohl None
424 endif
425
426 return
427endfunction
428" }}}
429" Snippet Support {{{
430let s:CodeSnippets = $HOME . "/.vim/snippets/"
431
432function! InsertSnippet()
433 let l:snippet_file = GetSnippetFile()
434
435 if l:snippet_file != "" && filereadable(l:snippet_file)
436 let linesread = line("$")
437 let l:old_cpoptions = &cpoptions
438 setlocal cpoptions-=a
439 execute "read " . l:snippet_file
440 let &cpoptions = l:old_cpoptions
441
442 let linesread = line("$") - linesread - 1
443 if linesread >= 0 && match(l:snippet_file, '\.\(ni\|noindent\)$') < 0
444 silent exe "normal =" . linesread . "+"
445 endif
446 endif
447endfunction
448
449function! EditSnippet()
450 let l:snippet_file = GetSnippetFile()
451
452 if l:snippet_file != "" && filereadable(l:snippet_file)
453 execute "update! | split | edit " . l:snippet_file
454 endif
455endfunction
456
457function! WriteSnippet()
458 let l:snippet_file = GetSnippetFile()
459
460 let @z = ""
461 normal! gv"zy
462 let l:snippet_text = split(@z, "\n")
463
464 if l:snippet_file != ""
465 call writefile(l:snippet_text, l:snippet_file)
466 endif
467endfunction
468
469function! GetSnippetFile()
470 if exists("b:current_syntax")
471 let l:snippet_dir = s:CodeSnippets . b:current_syntax
472 else
473 let l:snippet_dir = s:CodeSnippets . "default"
474 endif
475
476 if isdirectory(l:snippet_dir)
477 let l:snippet_file = input("choose snippet: ", l:snippet_dir, "file" )
478 return l:snippet_file
479 else
480 return ""
481 endif
482endfunction
483" }}}
484" Subversion Support {{{
485function! SVNDiff()
486 let fn = bufname("%")
487 let newfn = fn . ".HEAD"
488 let catstat = system("svn cat -r HEAD " . fn . " > " . newfn)
489 if stridx(catstat, "is not a working copy") > 0
490 echo "*** ERROR ***\n" . catstat
491 else
492 execute "vert diffsplit " . newfn
493 endif
494 let rmstat = system("rm " . newfn)
495endfunction
496" }}}
497" Unit Test Functions {{{
498" This should get move out of here eventually ~mcrute
499set errorformat=%f:%l:\ fail:\ %m,%f:%l:\ error:\ %m
500set makeprg=nosetests\ --machine-out
501
502function! RedBar()
503 hi RedBar ctermfg=white ctermbg=red guibg=red
504 echohl RedBar
505 echon repeat(" ",&columns - 1)
506 echohl
507endfunction
508
509function! GreenBar()
510 hi GreenBar ctermfg=white ctermbg=green guibg=green
511 echohl GreenBar
512 echon repeat(" ",&columns - 1)
513 echohl
514endfunction
515" }}}
516" {{{ Tab Completion
517function! InsertTabWrapper()
518 let col = col('.') - 1
519 if !col || getline('.')[col - 1] !~ '\k'
520 return "\<tab>"
521 else
522 return "\<c-p>"
523 endif
524endfunction
525
526inoremap <tab> <c-r>=InsertTabWrapper()<cr>
527inoremap <s-tab> <c-n>
528" }}}
529" {{{ Testing Support
530" Shamelessly ripped off of Gary Bernhart
531let g:show_tests = 0
532
533function! ClassToFilename(class_name)
534 let understored_class_name = substitute(a:class_name, '\(.\)\(\u\)', '\1_\U\2', 'g')
535 let file_name = substitute(understored_class_name, '\(\u\)', '\L\1', 'g')
536 return 'test_' . file_name . '.py'
537endfunction
538
539function! NameOfCurrentClass()
540 let save_cursor = getpos(".")
541 normal $<cr>
542 call PythonDec('class', -1)
543 let line = getline('.')
544 call setpos('.', save_cursor)
545 let match_result = matchlist(line, ' *class \+\(\w\+\)')
546 return match_result[1]
547endfunction
548
549function! ModuleTestPath()
550 let file_path = @%
551 let components = split(file_path, '/')
552 let filename = remove(components, -1)
553 let components = add(components, 'tests')
554 let test_path = join(components, '/')
555 return test_path
556endfunction
557
558function! TestFileForCurrentClass()
559 let class_name = NameOfCurrentClass()
560 let test_file_name = ModuleTestPath() . '/' . ClassToFilename(class_name)
561 return test_file_name
562endfunction
563
564function! TestFileForCurrentFile()
565 let filename = split(@%, '/')[-1]
566 let module_path = ModuleTestPath()
567 let components = split(module_path, '/')
568 let components = add(components, 'test_' . filename)
569 return join(components, '/')
570endfunction
571
572function! RunTests(target, args)
573 silent ! echo
574 exec 'silent ! echo -e "\033[1;36mRunning tests in ' . a:target . '\033[0m"'
575 set makeprg=nosetests
576 silent w
577 exec "make! " . a:target . " " . a:args
578endfunction
579
580function! RunTestsForFile(args)
581 if @% =~ 'test_'
582 call RunTests('%', a:args)
583 else
584 let test_file_name = TestFileForCurrentFile()
585 call RunTests(test_file_name, a:args)
586 endif
587endfunction
588
589function! RunAllTests(args)
590 silent ! echo
591 silent ! echo -e "\033[1;36mRunning all unit tests\033[0m"
592 set makeprg=nosetests
593 silent w
594 exec "make! tests.unit " . a:args
595endfunction
596
597function! JumpToError()
598 if getqflist() != []
599 for error in getqflist()
600 if error['valid']
601 break
602 endif
603 endfor
604 let error_message = substitute(error['text'], '^ *', '', 'g')
605 " silent cc!
606 let error_buffer = error['bufnr']
607 if g:show_tests == 1
608 exec ":vs"
609 exec ":buffer " . error_buffer
610 endif
611 exec "normal ".error['lnum']."G"
612 call RedBar()
613 echo error_message
614 else
615 call GreenBar()
616 echo "All tests passed"
617 endif
618endfunction
619
620function! JumpToTestsForClass()
621 exec 'e ' . TestFileForCurrentClass()
622endfunction
623
624let mapleader=","
625nnoremap <leader>m :call RunTestsForFile('--machine-out')<cr>:redraw<cr>:call JumpToError()<cr>
626nnoremap <leader>M :call RunTestsForFile('')<cr>
627nnoremap <leader>a :call RunAllTests('--machine-out')<cr>:redraw<cr>:call JumpToError()<cr>
628nnoremap <leader>A :call RunAllTests('')<cr>
629nnoremap <leader>t :call JumpToTestsForClass()<cr>
630nnoremap <leader><leader> <c-^>
631" }}}
632" vim:foldenable:foldmethod=marker: