Making the delete key work in screen (termcap capabilities)

I believe this is something I figured out long ago, and completely forgot since, so I had to figure it out again. I’m using a new virtualized Linux server from Slicehost, and as usual, I have some stuff running under Screen. Now, Screen is a crufty old program, but it’s immensely useful for leaving things running and detaching from them (and later reattaching), along with multiplexing several terminals into one.

But, I started having a problem I’d had before. Inside screen, my delete key wasn’t sending ^? (ascii 127), but it was sending ^[[3~ (the escape sequence for that key). Outside of screen, it was sending ^? as I'd expect. (I'm going to avoid the whole backspace [^H] versus delete [^?] argument here — OS X and Linux distributions seem to all come with it configured for delete out of the box these days, and that’s most of what I deal with.)

I poked around, and found some workarounds like this one, but I really want to fix it, rather than lying to it about my terminal type.

This did however remind me of what was wrong. My termcap (well, terminfo) was missing the proper capability for the delete key. So, I looked what the terminal type claimed by OS X’s Terminal.app was:


$ echo $TERM
xterm-color

I poked around some .screenrc examples and an old termcap file and composed this line to put in my .screenrc :

termcapinfo xterm-color kD=\E[3~

And it works! I didn’t even have to start a new screen session, I just detached and re-attached.

9 Comments

  1. sporksmith
    Posted August 16, 2008 at 11:42 am | Permalink

    I had the exact same problem and found this entry via googling “screen delete key”. Thanks a bunch!

  2. Posted October 13, 2008 at 9:49 am | Permalink

    Another satisfied reader! Borrowing my girlfriend’s iBook at the moment and this was driving me mad when ssh’ing into my linux box. Many thanks for sharing the tip.

  3. Joshua
    Posted March 11, 2009 at 10:28 am | Permalink

    Thanks for the explanation, links, and fix! Much appreciated.

  4. Chris
    Posted April 30, 2009 at 8:24 am | Permalink

    Thanks so much for this, it worked a treat!!

  5. Posted August 13, 2009 at 1:08 pm | Permalink

    Sir, you are a scholar and a gentleman. Thanks much.

  6. Stefan
    Posted October 1, 2009 at 10:23 pm | Permalink

    Thanks a lot !
    Greetings from southern Germany.

  7. Posted October 12, 2009 at 4:38 am | Permalink

    Yay !

    Thanks :D

  8. Ludovic Kuty
    Posted January 2, 2010 at 7:02 am | Permalink

    Googling “screen delete key”, it made my day. Thanks !

  9. larsr
    Posted May 6, 2010 at 10:46 pm | Permalink

    Thanks! This worked perfectly!
    (I’m ssh:ing from a Terminal.app on Mac OS X Snow Leopard laptop to a Ubuntu Feisty box and running screen on the ubuntu box. I put the termcap in the ~/.screenrc on my ubuntu box.)

One Trackback

  1. [...] This tip came from here. [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*