Skip to content

Instantly share code, notes, and snippets.

@stoeffel
Last active August 29, 2015 14:00
Show Gist options
  • Save stoeffel/7d37ba7ac40fba6ac8f1 to your computer and use it in GitHub Desktop.
Save stoeffel/7d37ba7ac40fba6ac8f1 to your computer and use it in GitHub Desktop.
switch between folders (i.e between view and controller in a MVC app)
" Example
" app/view/User.js
" switch to app/controller/User.js
function! SwitchBetween(from, to)
" TODO check if file exists
let firstPath = RemoveWDFromPath(expand('%:p'))
if match(firstPath, '\/'.a:from.'\/') != -1
let first = a:from
let sec = a:to
elseif match(firstPath, '\/'.a:to.'\/') != -1
let first = a:to
let sec = a:from
else
return
endif
let secPath = substitute(firstPath, '\/'.first.'\/', '\/'.sec.'\/', 'g')
echo secPath
execute "edit" secPath
endfunction
function! RemoveWDFromPath(path)
let cwd = substitute(getcwd(), '\/Users\/.*\/', '', '')
let cwd = substitute(getcwd(), '~\/', '', '')
return substitute(a:path, '.*' .cwd . '\/', '', '')
endfunction
nnoremap <Leader>vc :call SwitchBetween('view', 'controller')<cr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment