scrooloose (owner)

Revisions

gist: 213877 Download_button fork
public
Public Clone URL: git://gist.github.com/213877.git
Embed All Files: show embed
rogue.vim #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"this is in my ~/.vim/projects/rogue.vim
"in my vimrc i have a :runtime! projects/**/*.vim to source all my project files
 
"assumes each model class is in ./lib/foo.rb and the related
"spec (i.e. test) file is in ./spec/foo_spec.rb
 
autocmd bufnewfile,bufreadpost ~/projects/rogue/* call s:setup()
function! s:setup()
    command! -nargs=0 -buffer A call s:gotoAltFile('edit')
    command! -nargs=0 -buffer AS call s:gotoAltFile('split')
endfunction
 
function! s:gotoAltFile(action)
    let altFile = s:altFile()
    if filereadable(altFile)
        exec a:action . ' ' . altFile
    else
        echo "Alternate file not found: " . altFile
    endif
endfunction
 
function! s:altFile()
    let tail = expand("%:t")
    if tail =~# '_spec\.rb$'
        return "lib/" . substitute(tail, '_spec\ze.rb$', '', '')
    elseif tail =~# '\.rb$'
        return "spec/" . substitute(tail, '.rb$', '_spec.rb', '')
    endif
endfunction