Skip to content

Instantly share code, notes, and snippets.

@scrooloose
Created October 20, 2009 00:33
Show Gist options
  • Save scrooloose/213877 to your computer and use it in GitHub Desktop.
Save scrooloose/213877 to your computer and use it in GitHub Desktop.
"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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment