MacOS – How to send an arrow key in iTerm2

itermmacos

Is it possible to send an arrow key in iTerm2? I've been able to send almost any other character, by using either an escape character, such as \<C-a> or entering in the character directly, such as , but I haven't been able to figure out (or find on Google) how to send one of the arrow keys. For example, I would like to configure pressing

to send a tmux command of:

  • ctrla (ctrl-a being by prefix)

In other words, pressing cmd-up would navigate to the pane above the current one. How would I do this in iTerm2? That is, what "action" should I select (send hex codes? send text? send text with vim escape chars?) and text/code should I send?

enter image description here

Best Answer

If you're trying to send an to the terminal, I've been able to accomplish this using the Send Text with "vim" Special Chars option and then using the escape sequence \u000d[A. For example, I'm using it to clear the console and repeat the last command, so the full sequence I'm sending is:

clear\u000d\u001b[A\u001b[A\u000d

This first writes clear to the console and then submits with Enter as \u000d. Then, is sent twice to get the command submitted before the last clear command, and Enter is sent again to submit the retrieved command.

Hope this helps you. Cheers!