I have function to perform a git diff, after calling git diff I wish to emulate the following keypresses in the terminal window:
G
move to the end of the filea
appendq<cr>
type q to quit the "terminal scrolling mode" then entergg
return to the top of the file
Code:
function GitDiff()
terminal git diff --word-diff %
normal Gaq<Esc>gg
endfunction
:nmap <leader>t :call GitDiff()<cr>
However the keypresses dont seem to be executed as expected. I wonder if it needs a delay to wait for the terminal command to finish executing?
less
) launched bygit diff
? Why not rungit diff
using a function likesystemlist()
and write those contents to a scratch buffer instead? The terminal is quite tricky to automate, why do you think you need to use it here?term_sendkeys()
but the doc says "This requires for the job to be in the right state where it will do the right thing when receiving the keys" which I take it as this will send the keystrokes to the process running on the terminal and won't take normal-mode commands either...