Last active
March 13, 2018 16:33
-
-
Save andymass/bcd0a4956ed1a873d41f7265be6c6979 to your computer and use it in GitHub Desktop.
vim :terminal find-file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ $# -eq 0 ]] ; then | |
echo 'find-file: no file name specified' | |
exit 1 | |
fi | |
echo -en "\033]51;vim:$1\007" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Warning: this is a proof of concept.
Usage: source the script (modify if necessary). Then within vim
:terminal
type