Vim working natively on Android phones

Introduction

I own a HTC Dream. While one may discuss about its usability as a phone, it makes a great portable internet access machine. I have installed a debian chroot on that machine and used to boot it when I wanted to edit some stuff on the go - it has vim, git, svn and anything else you may need. It was, however, tiring to enable it each and every time I wanted to edit something, and it used up some memory that only could be freed by rebooting.

So I've grabbed the NDK and built Vim for Android

Screenshot

Warning

This only works for rooted phones. I have only tested it on G1 a.k.a. HTC Dream.

Download

Grab this archive with Vim 7.3 for Android.

Install using computer and adb

adb push vim-android.tar.gz /sdcard adb shell # su # cd / # tar -zxf /sdcard/vim-android.tar.gz # ^D

After this step, you should have a vim binary in /data/local/bin/vim - the directory should be in your $PATH, but you can ensure by typing:

# echo $PATH

Install using your phone only

Connect to your phone's shell using ConnectBot, Better Terminal or other software. Then type as following:

$ su # cd / # wget -O - http://gdr.geekhood.net/gdrwpl/heavy/vim-android.tar.gz | tar -zxf -

Details

Vim is built using NDK. This means it doesn't link statically to libc or any libraries that are already present. The only library it has built-in is ncurses.

All vim-specific files are placed in /data/local/usr/share. It's equipped in syntax highlighting for vim and shell files and some scripts I found in Ubuntu's vim distribution. More scripts can be installed to /data/local/usr/share/vim. The default vimrc file can also be found in that directory. The package also has a terminfo database stolen from Ubuntu - it's needed for color display. It's placed in /data/local/usr/share/terminfo

The list of options can be viewed here: vim --version output. Mouse support is available if you apply my patch to ConnectBot (vote for its inclusion into mainline!)

The binary size is about 1.3 MB.

Source

Put the content of the source pack in the sources/ directory of Android NDK. Chdir to that directory and issue ndk-build to produce Vim binary in libs/armeabi/vim.

The actual sources are in jni/ directory. NCurses is to be found in jni/ncurses/

Vim's auto/config.h and other automatically generated files are generated by ./configure running on ubuntu and tweaked manually. Similar thing is done to ncurses' curses.priv.h.

Simply relacing the source files with newer vim and rebuilding should do the trick of upgrading to the latest version. Adding new files to Android.mk may also be needed.