Fixing Shifted-Arrow Keys in 256-Color Terminals on Linux

The terminfo entry for “xterm-256color” that ships by default as part of ncurses-base on Debian Linux and its derivatives is a bit annoying. In particular, shifted up-arrow key presses work fine in some programs, but fail in others. It’s a bit of a gamble if Shift-Up works in joe, pico, vim, emacs, mutt, slrn, or what have you.

THis afternoon I got bored enough of losing my selected region in Emacs, because I forgot that I was typing in a terminal launched by a Linux desktop. SO I thought “what the heck… let’s give the FreeBSD termcap entry for xterm-256color a try”:

keramida> scp bsd:/etc/termcap /tmp/termcap-bsd
keramida> captoinfo -e $(                                  \
  echo $( grep '^xterm' termcap | sed -e 's/[:|].*//' ) |  \
  sed -e 's/ /,/g'                                         \
  ) /tmp/termcap  > /tmp/terminfo.src
keramida> tic /tmp/terminfo.src

Restarted my terminal, and quite unsurprisingly, the problem of Shift-Up keys was gone.

The broken xterm-256color terminfo entry from /lib/terminfo/x/xterm-256color is now shadowed by ~/.terminfo/x/xterm-256color, and I can happily keep typing without having to worry about losing mental state because of this annoying little misfeature of Linux terminfo entries.

The official terminfo database sources[1], also work fine. So now I think some extra digging is required to see what ncurses-base ships with. There’s definitely something broken in the terminfo entry of ncurses-base, but it will be nice to know which terminal capabilities the Linux package botched.


3 thoughts on “Fixing Shifted-Arrow Keys in 256-Color Terminals on Linux

  1. Mikhail

    Hello there! A nice idea. I was also frustrated by the fact that I can either have 256 colors OR shift+arrows working (with xterm-vt220). I’ve got FreeBSD’s termcap.src from their SVN (as I don’t have a machine running it). Your approach almost worked, except that I still don’t have “End” key working in Emacs, it’s being recognized as the key. Are you having the same issue?

  2. Mikhail

    Whoops, WordPress ate the key name in angled braces. The next to last sentence should end as “…it’s being recognized as the ‘select’ key”

  3. keramida Post author

    Hi Mikhail. I don’t have that Linux installation anymore, but I’ll give it a try and let you know. I think ‘End’ is recognized as something different from ‘End’ indeed.

Comments are closed.