Last active
August 29, 2015 14:00
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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