Tuesday, March 1, 2011

How To Set Up Vim To Work Well via iSSH

iSSH is of course an awesome ssh client which runs on iPad. Pair it with a Bluetooth keyboard and some kind of stand and you've got the ability to do all kinds of hacking on a remote server via your iPad. But if you use vim, you've got a challenge: Apple does not give developers access to the Escape key on the Bluetooth keyboard, according to the iSSH developer. Or, to put it another way, Apple hates vim for no reason.

iSSH includes an "Esc" key on-screen, but hitting the screen like that is lame, and, in the case of a sufficiently flimsy iPad stand, will cause your iPad to fall over. There's a much better way.

First, go into your connection configuration in iSSH, hit "Advanced," and set your term string to "xterm-ipad."

Next, copy /etc/terminfo/x/xterm to /etc/terminfo/x/xterm-ipad. This lets the server know that it can communicate with iSSH like a normal ssh session.

Then add this to your .vimrc:

  3 if &term == "xterm-ipad"
4 nnoremap <Tab> <Esc>
5 vnoremap <Tab> <Esc>gV
6 onoremap <Tab> <Esc>
7 inoremap <Tab> <Esc>`^
8 inoremap <Leader><Tab> <Tab>
9 endif

Big thanks to Alf Mikula and Doug McInnes for showing me how to fix this. The only thing to watch out for with this solution is that it doesn't break tab-completion. So if you do:

:r filena

And press Tab, you'll get :r filename. And if you keep hitting Tab, you keep getting tab-completion. So it's kind of a Tab dead zone, but beyond that caveat, it works beautifully.