Blog | Admin | Archives | Random | Recent | Thanks
    • The shape shifters in their usual form.
    • Clippering under moody clouds.
    • 🌊
    • The City

Screen and Vim with 256 colors

There are a few guides out and about about how to get your terminal up and running with 256 colors, which gives you a lot more options than the traditional 16 terminal colors that are enabled by default. I used several of these guides in coming up with my approach, but I had a few problems following these instructions. Eventually, through some trial and error, I found something that works, so I thought I’d share it here.

To get going quickly, you can just use my dotfiles, which I share on github and periodically update.

The key stuff I added for 256 colors are in these commits:

The key thing that was hard for me to get right was the tempcapinfo line in screenrc. The trial-and-error invovled putting my old termcapinfo and the new suggested termcapinfo together in different ways. Apparently, the correct answer was “append the new one to the old one” and then I was done. So, my screenrc’s termcapinfo line now looks like this:

termcapinfo xterm 'is=\E[r\E[m\E[2J\E[H\E[?7h\E[?1;4;6l:Co#256:AF=\E[38;5;%dm:AB=\E[48;5;%dm:tc=screen:'

If anyone out there understand what in the world is going on there, please enlighten us in the comments!

Auto-Updating GNU Screen Window Names

It took a bunch of searching a testing, but I got something that works for me and I like well. Instead of every screen window being called “bash” or being named manually, I now have them all named after the working directory. This is the magic:

PROMPT_COMMAND='echo -ne "\033k$(basename $PWD)\033\\"'

PROMPT_COMMAND gets run every time bash displays a prompt, and those particular escape characters do the magic.

To avoid crap outside of screen, I did this:

case ${TERM} in
screen)
export PROMPT_COMMAND='echo -ne "\033k$(basename $PWD)\033\\"'
;;
esac

Which is more general than it needs to be, but maybe I’ll expand it in the future.