Skip to main content
6 of 6
added 176 characters in body
Thunderbeef
  • 507
  • 4
  • 13

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:

  1. Open vim preemptively to not get error on load.
  2. While in terminal, start by writing echo -n '' >> ~/.vimrc, then put cursor between quotes and press control-v followed by Up, then enter to execute your command.
  3. Reload .vimrc with :e!, delete the last line with literal Up sequence, and p it wherever you want (in this case, into chansend function).

Upd: Another way: enter keys by hex code directly in vim:

  1. Find out your Up key byte sequence in terminal by piping it to hexdump -C (same method with echo as described above). This is important, because Up 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
  1. Enter every byte in vim by pressing C-v, followed by x, 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>")
Thunderbeef
  • 507
  • 4
  • 13