Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function! s:AlternateFile()
- let fn = substitute(expand('%'), "^".getcwd()."/", "", "")
- let head = fnamemodify(fn, ':h')
- let tail = fnamemodify(fn, ':t')
- if match(head, '^lib') >= 0
- return substitute(head, '^lib', 'test', '').'/test_'.tail
- elseif match(head, '^test') >= 0
- return substitute(head, '^test', 'lib', '').'/'.substitute(tail, '^test_', '', '')
- endif
- return ''
- endfunction
- function! s:Alternate(cmd)
- let file = s:AlternateFile()
- "if file != '' && filereadable(file)
- if a:cmd == 'T'
- let cmd = 'tabe'
- elseif a:cmd == 'S'
- let cmd = 'sp'
- else
- let cmd = 'e'
- endif
- exe ':'.cmd.' '.file
- "else
- "echomsg 'No alternate file is defined: '.file
- "endif
- endfunction
- function! s:Init(path)
- try
- command A :call s:Alternate('')
- command AE :call s:Alternate('E')
- command AS :call s:Alternate('S')
- command AV :call s:Alternate('V')
- command AT :call s:Alternate('T')
- catch /^Vim\%((\a\+)\)\=:E174/
- endtry
- endfunction
- function! s:Detect()
- let dir = getcwd()
- if filereadable(dir . '/config/environment.rb')
- " don't load if this is a rails project
- return 0
- endif
- if filereadable(dir . '/Rakefile') && isdirectory(dir . '/lib') && filereadable(dir . '/test/helper.rb')
- return s:Init(dir)
- endif
- return 0
- endfunction
- augroup nonRailsRubyDetect
- autocmd VimEnter * call s:Detect()
- augroup END
Add Comment
Please, Sign In to add comment