Add tabs to Xterm using GNU Screen

Xterm has always been my favourite terminal emulator. One thing I’ve always missed is the tabs support found on other terminals like konsole or gnome-terminal, that’s why from time to time I use gnome-terminal but after a while I realize that less is really more and come back to Xterm. A few days ago I found this blog post about adding tab support to Xterm using the GNU Screen utility and now I’ve got tabs too!

Here’s a little tutorial on how to have a tabbed version of Xterm using Screen.

First of all you need to get Screen. It might be already installed on your linux box. If that’s not your case chances are you can get it from your distro repositories. On Ubuntu try this:

$ sudo apt-get install screen

Now open up your Xterm terminal and type in the following command:

screen

You may be asked about something about the appearance of Screen (if i remember…), after that you won’t be asked again about that. After that you should see the same prompt you had before running the screen command. Now you can have many instance of your terminal on the same window. How, you might be wondering. Well, escape yourself with Ctrl+a and then use one of the following combinations:

  • Ctrl+c or c – create a new screen
  • Ctrl+n or n – switch to the next screen
  • Ctrl+p or p – switch to the previous screen
  • 0 to 9 – switch directly to the screen number (0,1,2,…,9)
  • A – change your screen name (A is uppercase)
  • Ctrl+w or w – show the screen list
  • Ctrl+” or – show an interactive screen list

That’s pretty awesome! But wait… there aren’t any tabs! Well… there kinda are, you just don’t see them, but you can easily switch between different instances escaping with Ctrl+a and hitting n or p. To actually see the tabs escape with Ctrl+a and try this:

: caption always '%w'

Now you can see your tabs. The one with an asterisk is the one that’s active. See the picture below:

There is a way to format your captions and give them a better look, or at least a more tabby look. Again escape with Ctrl+a and type this:

: caption always '%{= kB}%-Lw%?%{r}[%{G}%n*%f %t%?%{r}]%{= kB}%+Lw'

Looking good! Ok, now you can use tabs with Xterm but it seems really hard to remember all that “caption always ‘{= kB}…” stuff, there might be a better way! And yep, there is. You can edit a file called screenrc and put there all the options you want. Let’s edit that file with our favourite text editor:

$ nano ~/.screenrc

Where ~ stands for your $HOME directory. Now type down this:

caption always '%{= kB}%-Lw%?%{r}[%{G}%n*%f %t%?%{r}]%{= kB}%+Lw'
termcapinfo xterm|xterms|xs|rxvt ti@:te@

The first line changes the format style for our captions/tabs. The second line enables the normal scroll of Xterm so you should write it down too. Save the file and restart screen. There will be tabs! You can also run Screen when you first run Xterm, just use the -e switch:

xterm -e screen

And that’s pretty much it!

1 comment

  1. Great tip! Thanks a lot!

    — prensa Tue, 5 Jan 2010

Please insert the result of the arithmetical operation from the following image
Enter the result of the arithmetical operation from this image