Skip to main content
3 of 6
How to do it in vim directly
Thunderbeef
  • 507
  • 4
  • 13

First of all, you most likely need to use chansend() function. I don't have term_sendkeys() in my neovim instance, so it's probably from some plugin. 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.

Thunderbeef
  • 507
  • 4
  • 13