I don't have term_sendkeys()
in my neovim
instance, so I'll use chandsend()
in my example. Also, the i
is unnecessary, since this function can't put you into insert mode.
Now, regarding your problem. "\<Up>"
does indeed have some unexpected behavior inside double quotes. But, I managed to work around it like this:
- Open
vim
preemptively to not get error on load. - While in terminal, start by writing
echo -n '' >> ~/.vimrc
, then put cursor between quotes and presscontrol-v
followed byUp
, thenenter
to execute your command. - Reload
.vimrc
with:e!
, delete the last line with literalUp
sequence, andp
it wherever you want (in this case, intochansend
function).
Upd: Another way: enter keys by hex code directly in vim:
- Find out your
Up
key byte sequence in terminal by piping it tohexdump -C
(same method with echo as described above). This is important, becauseUp
key may produce different sequences based on your$TERM
value, shell, and system-global key remappings. Here's what mine looks like:
echo -n '^[OA' | hexdump -C
6 00000000 1b 4f 41 |.OA|
5 00000003
- Enter every byte in vim by pressing
C-v
, followed byx
, and then hex code. E.g.C-v x 1 b
for first byte, and so on...
This seem to work correctly:
call chansend(b:terminal_job_id, '^[OA' . "\<cr>")
Do not try to copy code from here, though. You need to get actual literal Up
sequence from your shell.
Upd.2: Actually, scratch almost all of above, and just specify bytes as hex sequences, like this:
call chansend(b:terminal_job_id, "\x1b\x4f\x41\<cr>")