Skip to content

Instantly share code, notes, and snippets.

@bcgraham
Created August 5, 2022 22:09
Show Gist options
  • Save bcgraham/8065dee27b523be6df113e47fd997138 to your computer and use it in GitHub Desktop.
Save bcgraham/8065dee27b523be6df113e47fd997138 to your computer and use it in GitHub Desktop.
Open a source location in vim
class Object
def vim
return unless File.chardev?('.vimpty') && respond_to?(:source_location) && source_location
message = %(\e]51;["call", "IrbApi_OpenBuf", #{source_location.inspect}]\a)
IO.write('.vimpty', message, mode: 'a')
end
end
function! MakeVimpty()
let ptybuf = term_start("NONE", {"term_name": "ptybuf", "hidden": 1, "term_kill": "quit"})
call term_setapi(ptybuf, "IrbApi_")
call system("ln -fs ".job_info(term_getjob(ptybuf))['tty_out']." .vimpty")
exe "autocmd BufUnload <buffer=" . ptybuf . "> call delete('.vimpty')"
endfunction
function IrbApi_OpenBuf(bufnum, args)
let open_str = fnamemodify(a:args[0], ":.")
if exists('a:args[1]')
let open_str = "+". a:args[1] . " " . open_str
endif
silent exe "vert drop " . open_str
endfunc
call MakeVimpty()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment