Created
October 2, 2009 01:22
-
-
Save hokaccha/199378 to your computer and use it in GitHub Desktop.
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
" HTMLとかでドキュメントルートからの絶対パスのファイルを開く(gfみたいな感じで) | |
" 絶対パスじゃなかったら(/で始まってなかったら)gfと同じ | |
" ドキュメントルートのディレクトリは配列で複数指定できる。 | |
let s:root_dirs = [$HOME.'/dev/site/localhost/test'] | |
function! GotoAbsFile() | |
let filename = expand('<cfile>') | |
let filepath = filename | |
if (match(filename, '^/') != -1) | |
for dir in s:root_dirs | |
if match(expand("%:p:h"), dir) != -1 && isdirectory(dir) == 1 | |
let filepath = dir . filename | |
break | |
endif | |
endfor | |
endif | |
if filereadable(filepath) | |
execute 'edit ' . filepath | |
else | |
echohl ErrorMsg | |
echo 'no such file ' . filename | |
echohl None | |
endif | |
endfunction | |
nnoremap gaf :<C-u>call GotoAbsFile()<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment