Skip to content

Instantly share code, notes, and snippets.

@hokaccha
Created October 2, 2009 01:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hokaccha/199378 to your computer and use it in GitHub Desktop.
Save hokaccha/199378 to your computer and use it in GitHub Desktop.
" 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