mirror of
1
0
Fork 0
ultimate-vim/sources_non_forked/open_file_under_cursor.vim/plugin/open_file_under_cursor.vim

29 lines
805 B
VimL
Raw Normal View History

2012-08-16 23:41:25 -04:00
" ----- Emulate 'gf' but recognize :line format -----
function! GotoFile(w)
let curword = expand("<cfile>")
if (strlen(curword) == 0)
return
endif
let matchstart = match(curword, ':\d\+$')
if matchstart > 0
let pos = '+' . strpart(curword, matchstart+1)
let fname = strpart(curword, 0, matchstart)
else
let pos = ""
let fname = curword
endif
" Open new window if requested
if a:w == "new"
new
endif
" Use 'find' so path is searched like 'gf' would
execute 'find ' . pos . ' ' . fname
endfunction
set isfname+=: " include colon in filenames
" Override vim commands 'gf', '^Wf', '^W^F'
nnoremap gf :call GotoFile("")<CR>
nnoremap <C-W>f :call GotoFile("new")<CR>
nnoremap <C-W><C-F> :call GotoFile("new")<CR>