Skip to content

Instantly share code, notes, and snippets.

@Raimondi
Created February 22, 2011 01:53
Show Gist options
  • Save Raimondi/838089 to your computer and use it in GitHub Desktop.
Save Raimondi/838089 to your computer and use it in GitHub Desktop.
Better gf
" Always edit a file on gf, but be nice and ask
map gf :<C-U>call GoFile()<CR>
function! GoFile()
try
normal! gf
catch /^Vim\%((\a\+)\)\=:E447/
let q = substitute(v:exception,'^Vim\%((\a\+)\)\=:E\d\+: \(.*\)','\1','') . ', would you like to create it?'
try
buffer <cfile>
catch /^Vim\%((\a\+)\)\=:E94/
if confirm(q ,"&Yes\n&No\n&Cancel",3) == 1
exec 'edit '.expand('%:p:h').'/'.expand('<cfile>')
endif
endtry
endtry
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment