Vim and Jailkit

Vim and JailkitRecently I installed Jailkit on Ubuntu 12.04 and then tried to use the vim editor to edit files as the jailed user (specifically a user jailed with the bash shell) and vim was behaving oddly.

The colors on the terminal were just a gray (default color) and a bold white. After a little digging I found out this is how vim does syntax highlighting when it thinks that only two colors are available.

Also, I was having trouble with the arrow keys not working – I could move around with HJKL but there also seemed to be lag and vim was hanging or would hang sometimes and was not responsive.

I typed in set terminal and it told me ansi which is the default, “dumb” terminal. You can change vim to another terminal type, like xterm a few ways.

  1. Inside vim type :set term=xterm and that should do it
  2. Edit your .vimrc file (in your home directory) and add set term=xterm
  3. Before launching vim type export TERM=xterm to set an environmental variable
  4. Add that last command (export TERM=xterm) into one of your startup files like ‘~/.profileor '~/.bashrc

This fixed the issue with the arrow keys, the lag and hanging, but I still only had two colors. After many hours of digging I realized that with Jailkit on Ubuntu even if you do jk_init -v /home/jail editors to install joe and vim and emacs you still get this problem. I did a stack trace on vim and even turned on debugging and logging and still could not find the issue.

After realizing it was a terminal detection issue and looking though how Unix and Linux determine the terminal type I noticed, that at least on Ubuntu, the files it needs for that operation of terminal capability detection are in the terminfo directory at /lib/terminfo/ – this may be a different directory on other distributions / flavors of linux – the directory should exist and have a lot of subdirectories and not be empty. Once you find the right directory you can copy it to inside the jail using the jk_cp command, so if your jail is in /home/jail you can use:

jk_cp -v -f /home/jail /lib/terminfo/

Related Posts:

This entry was posted in Server Admin and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *