I want to map a keyboard shortcut to execute the last command in a terminal buffer that I have open.
I've made some progress: I am storing the buffer's channel id correctly but when I try to send keys to the terminal (up arrow and enter) they always appear as literal characters in the terminal rather than actually going to the previous command and executing it.
" remember the chan id (buffer id) of the last terminal buffer
augroup Terminal
au!
au TermOpen * let g:last_terminal_chan_id = b:terminal_job_id
augroup END
" WIP: doesn't work yet
function! REPLSend()
" the following commented out lines were taken from another plugin that sends keys to a terminal - it doesn't seem to work
" let isnormal = mode() ==# 'n'
" let curwin = winnr()
" exe "sb " . g:last_terminal_chan_id
" call cursor('$', 1)
" exe curwin . 'wincmd w'
" if isnormal
" stopinsert
" endif
" call chansend(g:last_terminal_chan_id, '<Up>' . '\n')
call term_sendkeys(g:last_terminal_chan_id, "i\<Up>\<cr>")
endfunction
command! REPLSendLine call REPLSend()
nnoremap <silent> <f5> :REPLSendLine<cr>
{keys} are translated as key sequences. For example, "\<c-x>" means the character CTRL-X.
, so I would expect this to "work"!!
too...