0

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.

2

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.

  • 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 Jan 19 '14 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.