Skip to content

Instantly share code, notes, and snippets.

@eagletmt
Last active December 17, 2015 17:09
Show Gist options
  • Save eagletmt/5643532 to your computer and use it in GitHub Desktop.
Save eagletmt/5643532 to your computer and use it in GitHub Desktop.
nnoremap <C-g> :<C-u>call <SID>ruby_gf()<CR>
function! s:ruby_gf()
let l:saved_isfname = &l:isfname
setlocal isfname+=:
let l:cfile = expand('<cfile>')
let &l:isfname = l:saved_isfname
let l:match = matchlist(l:cfile, '\(\f\+\):\(\d\+\)')
normal! gf
if !empty(l:match)
execute l:match[2]
normal! zz
endif
endfunction
nnoremap <C-g> :<C-u>call <SID>ruby_gf()<CR>
function! s:ruby_gf()
let l:saved_isfname = &l:isfname
setlocal isfname+=:
let l:cfile = expand('<cfile>')
let &l:isfname = l:saved_isfname
let l:match = matchlist(l:cfile, '\(\f\+\):\(\d\+\)')
normal! gf
if !empty(l:match)
execute l:match[2]
normal! zz
endif
endfunction
function! s:editjump(path)
if filereadable(a:path)
let l:path = a:path
let l:lineno = 1
else
let l:match = matchlist(a:path, '^\([^:]*\):\(\d\+\)$')
let l:path = l:match[1]
let l:lineno = l:match[2]
endif
let l:escaped_path = fnameescape(l:path)
silent execute 'doautocmd BufReadPre' l:escaped_path
execute 'edit' l:escaped_path
silent execute 'doautocmd BufReadPost' l:escaped_path
execute l:lineno
normal! zz
endfunction
augroup vimrc-editjump
autocmd!
autocmd BufReadCmd *:\d\+ call s:editjump(expand('<amatch>'))
augroup END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment