mirror of https://github.com/amix/vimrc.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.2 KiB
41 lines
1.2 KiB
" ----- 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
|
|
|
|
" check exists file.
|
|
if filereadable(fname)
|
|
let fullname = fname
|
|
else
|
|
" try find file with prefix by working directory
|
|
let fullname = getcwd() . '/' . fname
|
|
if ! filereadable(fullname)
|
|
" the last try, using current directory based on file opened.
|
|
let fullname = expand('%:h') . '/' . fname
|
|
endif
|
|
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>
|
|
|