2

I am using tmux a lot, and I have already managed to tune my OS X terminal to send the correct key codes for Ctrl+left and right arrow (\033b and \033f). I found those information on the web. However, I also need Ctrl+up and down to work correctly. How do I find out which key codes tmux expects? The TERM variable is set to screen while inside of tmux. Can I query the terminal database on my Linux machine for the codes?

At the moment, my OS X terminal simply sends arrow left and right, without the Ctrl modifier.

1

1 Answer 1

4

I just found that tmux seems to expect xterm keycodes, not minding the screen terminal type. Hence I just punched the keys in xterm, using Ctrl-V as a prefix and got these codes:

  • left key: ^[[D
  • right key: ^[[C
  • up key: ^[[A
  • down key: ^[[B
  • C-left: ^[[1;5D
  • C-right: ^[[1;5C
  • C-up: ^[[1;5A
  • C-down: ^[[1;5B

I can now configure OS X terminal to send those key codes, and tmux works fine. However, other apps running in tmux will break, because they don't expect to get xterm key codes. I found a workaround in the ArchWiki, which suggests to create your own terminfo entry. I will try that.

Edit: The tmux FAQ got me going, and I added the following two lines to my ~/.tmux.conf:

set -g default-terminal "xterm-256color"
setw -g xterm-keys on                   

Now I can use C-arrows in tmux, bash, emacs and other programs.

One more edit: Since tmux does not support bce (background color erasing), I needed to make my own terminfo, called xterm-256color-nobce:

infocmp xterm-256color | sed 's/bce, //' > xterm-256color-nobce
sudo tic ./xterm-256color-nobce

And made sure to use that as my default TERM value.

2
  • 1
    One more comment: I tried the ArchWiki approach, and it at least throws no errors. tmux now accepts C-arrow for resizing. However, bash, emacs and all other apps now report C-arrow as arrow. Terminal type is set to xterm-screen-256color, derived from screen-256color.
    – Arne
    Commented Jan 19, 2014 at 17:02
  • I have been looking more about the keycodes, and any light you can shed about why ^[[1;5A is Ctrl+Up, and so on would be very helpful. What is 1;5 in that? Another confusion I had was, if Ctrl is ^, and Alt is ^[, how does this system differentiate between Ctrl+[ key and Alt, and other such obvious problems? Commented May 11, 2020 at 10:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .