Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@andymass
Last active March 13, 2018 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andymass/bcd0a4956ed1a873d41f7265be6c6979 to your computer and use it in GitHub Desktop.
Save andymass/bcd0a4956ed1a873d41f7265be6c6979 to your computer and use it in GitHub Desktop.
vim :terminal find-file
#!/bin/bash
if [[ $# -eq 0 ]] ; then
echo 'find-file: no file name specified'
exit 1
fi
echo -en "\033]51;vim:$1\007"
function! TerminalFindFileCB(chan, msg)
let l:file = matchstr(a:msg, "\<esc>]51;vim:".'\zs.\{-}\ze[\x7\x1b]')
if empty(l:file) | return | endif
let l:file = fnameescape(l:file)
if filereadable(l:file)
execute 'drop' l:file
else
echoerr 'terminalfindfile:' l:file 'is not readable'
endif
endfunction
" use the first :terminal found
let s:term_buf = get(term_list(), 0, -1)
if s:term_buf > 0
call ch_setoptions(job_getchannel(term_getjob(s:term_buf)),
\ {"callback": function("TerminalFindFileCB")})
else
echoerr 'terminalfindfile: no terminal buffer'
endif
@andymass
Copy link
Author

andymass commented Mar 12, 2018

Warning: this is a proof of concept.

Usage: source the script (modify if necessary). Then within vim :terminal type

$ find-file filename.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment