summaryrefslogtreecommitdiff
path: root/.vimrc
diff options
context:
space:
mode:
authorMike Crute <mcrute@gmail.com>2010-05-02 18:50:09 -0400
committerMike Crute <mike@crute.us>2010-05-02 18:50:09 -0400
commit7dfa5d2bd6acff9225ff08145684a6de1ed449a5 (patch)
treedabf845a6cba61d20fdebf599a485ac76834a908 /.vimrc
parentcef6cee3b67b5e5a51b4e12fdd740a1dddeadfb1 (diff)
downloaddotfiles-7dfa5d2bd6acff9225ff08145684a6de1ed449a5.tar.bz2
dotfiles-7dfa5d2bd6acff9225ff08145684a6de1ed449a5.tar.xz
dotfiles-7dfa5d2bd6acff9225ff08145684a6de1ed449a5.zip
Splitting out testing and templates from vimrc file
Diffstat (limited to '.vimrc')
-rw-r--r--.vimrc386
1 files changed, 49 insertions, 337 deletions
diff --git a/.vimrc b/.vimrc
index 95df7e7..31a9783 100644
--- a/.vimrc
+++ b/.vimrc
@@ -11,7 +11,8 @@ source ~/.vim/author_info.vim
11 11
12" Syntax Highlighting {{{ 12" Syntax Highlighting {{{
13syntax on 13syntax on
14colorscheme mcrute_slate 14"colorscheme mcrute_slate
15colorscheme fruity
15set background=dark 16set background=dark
16 17
17" MacVim gets its transparency settings all horked up if we don't 18" MacVim gets its transparency settings all horked up if we don't
@@ -25,7 +26,7 @@ if has("gui_macvim") && has("gui_running")
25 set transparency=10 26 set transparency=10
26 set lines=65 27 set lines=65
27 set columns=100 28 set columns=100
28 set guifont=Monaco:h10.00 29 set guifont=Monaco,bold:h10.00
29 set go-=T 30 set go-=T
30 colorscheme mcrute 31 colorscheme mcrute
31endif 32endif
@@ -39,6 +40,25 @@ if has("gui_gtk") && has("gui_running")
39 set guifont=Monospace\ 8 40 set guifont=Monospace\ 8
40 set guioptions=aegimrLt 41 set guioptions=aegimrLt
41endif 42endif
43
44" AGI PD Template Files
45autocmd BufNewFile,BufRead,BufReadPost *.pd
46 \ set syntax=pyfusion
47
48" Apache Files in Apache dirs
49autocmd BufNewFile,BufRead,BufReadPost /*apache*
50 \ set syntax=apache
51
52" Jinja2 Templates
53autocmd BufNewFile,BufRead,BufReadPost *.tmpl
54 \ set syntax=jinja
55
56" Python Files
57autocmd BufNewFile,BufRead *.py
58 \ setlocal foldmarker=#{,#}
59
60autocmd Filetype html,xml,xsl
61 \ source ~/.vim/scripts/scripts/closetag.vim
42" }}} 62" }}}
43" General Settings {{{ 63" General Settings {{{
44set backspace=indent,eol,start 64set backspace=indent,eol,start
@@ -53,6 +73,7 @@ set backup
53set directory=~/.vim/tmp,~/.tmp,~/tmp,/var/tmp,/tmp 73set directory=~/.vim/tmp,~/.tmp,~/tmp,/var/tmp,/tmp
54set backupdir=~/.vim/tmp,~/.tmp,~/tmp,/var/tmp,/tmp 74set backupdir=~/.vim/tmp,~/.tmp,~/tmp,/var/tmp,/tmp
55set vb t_vb= 75set vb t_vb=
76let mapleader=","
56" }}} 77" }}}
57" Search Settings {{{ 78" Search Settings {{{
58set hlsearch 79set hlsearch
@@ -65,14 +86,12 @@ set smartcase
65set autoindent 86set autoindent
66set expandtab 87set expandtab
67set shiftwidth=4 88set shiftwidth=4
68"set smartindent " Screws up python indenting
69set smarttab 89set smarttab
70set softtabstop=4 90set softtabstop=4
71set tabstop=4 91set tabstop=4
72" }}} 92" }}}
73" Visual Display {{{ 93" Visual Display {{{
74set laststatus=2 94set laststatus=2
75"set list
76set noequalalways 95set noequalalways
77set nowrap 96set nowrap
78set number 97set number
@@ -96,24 +115,16 @@ filetype indent on
96 115
97" Use verital splits for file explorer 116" Use verital splits for file explorer
98let g:explVertical=1 117let g:explVertical=1
99" }}}
100" File Type -> Highlighting Maps {{{
101" AGI PD Template Files
102autocmd BufNewFile,BufRead,BufReadPost *.pd
103 \ set syntax=pyfusion
104
105" Apache Files in Apache dirs
106autocmd BufNewFile,BufRead,BufReadPost /*apache*
107 \ set syntax=apache
108 118
109" Python Files 119" Set closing tag style for closetag.vim
110autocmd BufNewFile,BufRead *.py 120let g:closetag_html=1
111 \ setlocal foldmarker=#{,#}
112" }}} 121" }}}
113" Custom Commands {{{ 122" Custom Commands {{{
114" Cleanup windows crap from line endings 123" Cleanup windows crap from line endings
124command TrimSpaces %s/\s\+$//e
115command FixLineEnd %s/ //gi 125command FixLineEnd %s/ //gi
116command PEP8 call IsPEP8() 126command PEP8 call IsPEP8()
127command W write
117" }}} 128" }}}
118" Folding Settings {{{ 129" Folding Settings {{{
119set foldenable 130set foldenable
@@ -123,47 +134,16 @@ set foldmethod=marker
123" Striving for Python Zen {{{ 134" Striving for Python Zen {{{
124let python_highlight_all=1 135let python_highlight_all=1
125 136
126" Code completion! 137autocmd FileType python
127autocmd FileType python set omnifunc=pythoncomplete#Complete 138 \ set omnifunc=pythoncomplete#Complete
128inoremap <Nul> <C-x><C-o>
129
130" Remove trailing spaces from *.py files for PEP8 compliance
131function! TrimSpaces()
132 :%s/\s\+$//e
133endfunction
134
135"autocmd BufWritePre *.py call TrimSpaces
136 139
137" Run pep8 checks if we can 140function! CheckIt()
138function! IsPEP8() 141 if executable("pylint")
139 if executable("agi-pep8.py") 142 !pylint %
143 elseif executable("agi-pep8.py")
140 !agi-pep8.py % 144 !agi-pep8.py %
141 endif 145 endif
142endfunction 146endfunction
143
144" Run pylint on the file
145if executable("pylint")
146" autocmd BufWritePost *.py !pylint -rn %
147" autocmd BufRead *.py set makeprg=pylint\ -rn\ %
148elseif executable("agi-pep8.py")
149" autocmd BufWritePost *.py !agi-pep8.py %
150" autocmd BufRead *.py set makeprg=agi-pep8.py\ %
151endif
152
153" Allow us to gf into import statements
154if has("python")
155python << EOF
156import os, sys, vim
157for p in sys.path:
158 if os.path.isdir(p):
159 vim.command(r"set path+=%s" % (p.replace(" ", r"\ ")))
160EOF
161endif
162" }}}
163" Automatic Commands {{{
164"autocmd BufWinLeave * silent! mkview
165"autocmd BufWinEnter * silent! loadview
166"autocmd FileType python compiler nose
167" }}} 147" }}}
168" Line and Column Highlighting {{{ 148" Line and Column Highlighting {{{
169"autocmd BufEnter * call SetColumnHighlighting(1) 149"autocmd BufEnter * call SetColumnHighlighting(1)
@@ -286,300 +266,32 @@ function! Cream_listchars_init()
286endfunction 266endfunction
287call Cream_listchars_init() 267call Cream_listchars_init()
288" }}} 268" }}}
289" Template Support {{{ 269" {{{ Mercurial Support
290let s:Template_Directory = $HOME . '/.vim/templates/' 270nnoremap <leader>qs :!hg qseries
291 271nnoremap <leader>qS :!hg status
292function! SubstituteTag(pos1, pos2, tag, replacement)
293 let linenumber = a:pos1
294
295 while linenumber <= a:pos2
296 let line = getline(linenumber)
297 let start = 0
298
299 while match(line,a:tag,start) >= 0
300 let frst = match(line, a:tag, start)
301 let last = matchend(line, a:tag, start)
302
303 if frst !=- 1
304 let part1 = strpart(line, 0, frst)
305 let part2 = strpart(line, last)
306 let line = part1 . a:replacement.part2
307 let start = strlen(part1) + strlen(a:replacement)
308 endif
309 endwhile
310
311 call setline(linenumber, line)
312 let linenumber = linenumber + 1
313 endwhile
314endfunction
315 272
316function! InsertTemplate(template, header) 273function! HGNewPatch()
317 let templatefile = s:Template_Directory 274 let dirty_copy = system(join(["hg st", "wc -l", "awk '{print $1}'"], '|')) > 0
318 275
319 if exists("b:current_syntax") 276 let patch_name = input('Patch name: ')
320 let templatefile = templatefile . b:current_syntax . '/' . a:template 277 let commit_message = input('Commit message: ')
321 else
322 let templatefile = templatefile . 'default/' . a:template
323 endif
324 278
325 if filereadable(templatefile) 279 if dirty_copy && input('Force create patch (y/n)? ') == 'y'
326 let length = line("$") 280 let messages = system("hg qnew -f -m '".commit_message."' ".patch_name)
327 let pos1 = line(".") + 1
328 let l:old_cpoptions = &cpoptions
329 setlocal cpoptions-=a
330
331 if a:header
332 :goto 1
333 let pos1 = 1
334 exe '0read ' . templatefile
335 else
336 exe 'read ' . templatefile
337 endif
338
339 let &cpoptions = l:old_cpoptions
340 let length = line("$") - length
341 let pos2 = pos1 + length - 1
342
343 call SubstituteTag(pos1, pos2, '|FILENAME|', expand("%:t"))
344 call SubstituteTag(pos1, pos2, '|DATE|', strftime('%x'))
345 call SubstituteTag(pos1, pos2, '|TEXTDATE|', strftime('%B %d, %Y'))
346 call SubstituteTag(pos1, pos2, '|DATETIME|', strftime('%x %X %Z'))
347 call SubstituteTag(pos1, pos2, '|TIME|', strftime('%X %Z'))
348 call SubstituteTag(pos1, pos2, '|YEAR|', strftime('%Y'))
349 call SubstituteTag(pos1, pos2, '|AUTHOR|', g:AuthorName)
350 call SubstituteTag(pos1, pos2, '|EMAIL|', g:Email)
351 call SubstituteTag(pos1, pos2, '|AUTHORREF|', g:AuthorRef)
352 call SubstituteTag(pos1, pos2, '|PROJECT|', g:Project)
353 call SubstituteTag(pos1, pos2, '|COMPANY|', g:Company)
354 call SubstituteTag(pos1, pos2, '|COPYRIGHTHOLDER|', g:CopyrightHolder)
355
356 exe ':' . pos1
357 normal 0
358
359 let linenumber = search('|CURSOR|')
360
361 if linenumber >= pos1 && linenumber <= pos2
362 let pos1 = match(getline(linenumber), "|CURSOR|")
363
364 if matchend(getline(linenumber), "|CURSOR|") == match(getline(linenumber), "$")
365 silent! s/|CURSOR|//
366 :startinsert!
367 else
368 silent s/|CURSOR|//
369 call cursor(linenumber, pos1 + 1)
370 :startinsert
371 endif
372 endif
373 else 281 else
374 echohl WarningMsg | echo 'template file '.templatefile.' does not exist or is not readable'| echohl None 282 let messages = system("hg qnew -m '".commit_message."' ".patch_name)
375 endif
376
377 return
378endfunction
379" }}}
380" Snippet Support {{{
381let s:CodeSnippets = $HOME . "/.vim/snippets/"
382
383function! InsertSnippet()
384 let l:snippet_file = GetSnippetFile()
385
386 if l:snippet_file != "" && filereadable(l:snippet_file)
387 let linesread = line("$")
388 let l:old_cpoptions = &cpoptions
389 setlocal cpoptions-=a
390 execute "read " . l:snippet_file
391 let &cpoptions = l:old_cpoptions
392
393 let linesread = line("$") - linesread - 1
394 if linesread >= 0 && match(l:snippet_file, '\.\(ni\|noindent\)$') < 0
395 silent exe "normal =" . linesread . "+"
396 endif
397 endif 283 endif
398endfunction
399
400function! EditSnippet()
401 let l:snippet_file = GetSnippetFile()
402 284
403 if l:snippet_file != "" && filereadable(l:snippet_file) 285 if v:shell_error != 0
404 execute "update! | split | edit " . l:snippet_file 286 hi RedBar ctermfg=white ctermbg=red guibg=red
405 endif 287 echohl RedBar
406endfunction 288 echo messages
407 289 echohl
408function! WriteSnippet()
409 let l:snippet_file = GetSnippetFile()
410
411 let @z = ""
412 normal! gv"zy
413 let l:snippet_text = split(@z, "\n")
414
415 if l:snippet_file != ""
416 call writefile(l:snippet_text, l:snippet_file)
417 endif
418endfunction
419
420function! GetSnippetFile()
421 if exists("b:current_syntax")
422 let l:snippet_dir = s:CodeSnippets . b:current_syntax
423 else
424 let l:snippet_dir = s:CodeSnippets . "default"
425 endif
426
427 if isdirectory(l:snippet_dir)
428 let l:snippet_file = input("choose snippet: ", l:snippet_dir, "file" )
429 return l:snippet_file
430 else
431 return ""
432 endif
433endfunction
434" }}}
435" Subversion Support {{{
436function! SVNDiff()
437 let fn = bufname("%")
438 let newfn = fn . ".HEAD"
439 let catstat = system("svn cat -r HEAD " . fn . " > " . newfn)
440 if stridx(catstat, "is not a working copy") > 0
441 echo "*** ERROR ***\n" . catstat
442 else 290 else
443 execute "vert diffsplit " . newfn 291 echo
444 endif 292 endif
445 let rmstat = system("rm " . newfn)
446endfunction 293endfunction
447" }}} 294" }}}
448" Unit Test Functions {{{
449" This should get move out of here eventually ~mcrute
450set errorformat=%f:%l:\ fail:\ %m,%f:%l:\ error:\ %m
451set makeprg=nosetests\ --machine-out
452
453function! RedBar()
454 hi RedBar ctermfg=white ctermbg=red guibg=red
455 echohl RedBar
456 echon repeat(" ",&columns - 1)
457 echohl
458endfunction
459
460function! GreenBar()
461 hi GreenBar ctermfg=white ctermbg=green guibg=green
462 echohl GreenBar
463 echon repeat(" ",&columns - 1)
464 echohl
465endfunction
466" }}}
467" {{{ Tab Completion
468function! InsertTabWrapper()
469 let col = col('.') - 1
470 if !col || getline('.')[col - 1] !~ '\k'
471 return "\<tab>"
472 else
473 return "\<c-p>"
474 endif
475endfunction
476
477inoremap <tab> <c-r>=InsertTabWrapper()<cr>
478inoremap <s-tab> <c-n>
479" }}}
480" {{{ Testing Support
481" Shamelessly ripped off of Gary Bernhart
482let g:show_tests = 0
483
484function! ClassToFilename(class_name)
485 let understored_class_name = substitute(a:class_name, '\(.\)\(\u\)', '\1_\U\2', 'g')
486 let file_name = substitute(understored_class_name, '\(\u\)', '\L\1', 'g')
487 return 'test_' . file_name . '.py'
488endfunction
489
490function! NameOfCurrentClass()
491 let save_cursor = getpos(".")
492 normal $<cr>
493 call PythonDec('class', -1)
494 let line = getline('.')
495 call setpos('.', save_cursor)
496 let match_result = matchlist(line, ' *class \+\(\w\+\)')
497 return match_result[1]
498endfunction
499
500function! ModuleTestPath()
501 let file_path = @%
502 let components = split(file_path, '/')
503 let filename = remove(components, -1)
504 let components = add(components, 'tests')
505 let test_path = join(components, '/')
506 return test_path
507endfunction
508
509function! TestFileForCurrentClass()
510 let class_name = NameOfCurrentClass()
511 let test_file_name = ModuleTestPath() . '/' . ClassToFilename(class_name)
512 return test_file_name
513endfunction
514
515function! TestFileForCurrentFile()
516 let filename = split(@%, '/')[-1]
517 let module_path = ModuleTestPath()
518 let components = split(module_path, '/')
519 let components = add(components, 'test_' . filename)
520 return join(components, '/')
521endfunction
522
523function! RunTests(target, args)
524 silent ! echo
525 exec 'silent ! echo -e "\033[1;36mRunning tests in ' . a:target . '\033[0m"'
526 set makeprg=nosetests
527 silent w
528 exec "make! " . a:target . " " . a:args
529endfunction
530
531function! RunTestsForFile(args)
532 if @% =~ 'test_'
533 call RunTests('%', a:args)
534 else
535 let test_file_name = TestFileForCurrentFile()
536 call RunTests(test_file_name, a:args)
537 endif
538endfunction
539
540function! RunAllTests(args)
541 silent ! echo
542 silent ! echo -e "\033[1;36mRunning all unit tests\033[0m"
543 set makeprg=nosetests
544 silent w
545 exec "make! tests.unit " . a:args
546endfunction
547
548function! JumpToError()
549 if getqflist() != []
550 for error in getqflist()
551 if error['valid']
552 break
553 endif
554 endfor
555 let error_message = substitute(error['text'], '^ *', '', 'g')
556 " silent cc!
557 let error_buffer = error['bufnr']
558 if g:show_tests == 1
559 exec ":vs"
560 exec ":buffer " . error_buffer
561 endif
562 exec "normal ".error['lnum']."G"
563 call RedBar()
564 echo error_message
565 else
566 call GreenBar()
567 echo "All tests passed"
568 endif
569endfunction
570
571function! JumpToTestsForClass()
572 exec 'e ' . TestFileForCurrentClass()
573endfunction
574
575let mapleader=","
576nnoremap <leader>m :call RunTestsForFile('--machine-out')<cr>:redraw<cr>:call JumpToError()<cr>
577nnoremap <leader>M :call RunTestsForFile('')<cr>
578nnoremap <leader>a :call RunAllTests('--machine-out')<cr>:redraw<cr>:call JumpToError()<cr>
579nnoremap <leader>A :call RunAllTests('')<cr>
580nnoremap <leader>t :call JumpToTestsForClass()<cr>
581nnoremap <leader><leader> <c-^>
582" }}}
583" Key Bindings {{{ 295" Key Bindings {{{
584set pastetoggle=<F12> 296set pastetoggle=<F12>
585 297