Friday, August 20, 2010

Native vim for android

Update: The vim binary has moved to the downloads page.

Update: Created a code.google.com project to keep stuff like this. Also, I got color syntax hilighting to work. See the README.txt in the vim/ directory of the repository.

Tonight I managed to compile vim to run natively on my android phone! My phone is rooted and running cyanogenmod CM6 rc3. Rooting is necessary to run vim, but cyanogen probably isn't necessary.

First I had to compile ncurses using the ndk. Follow that link and compile ncurses the way I did if you want to have any hope of compiling vim using these instructions.

Once I had ncurses built, I had to make just a few changes to vim to get it to work.

I downloaded vim from the mercurial archive, which as of today is pretty much the same as the 7.3 release, I think. I figured out how to call configure by trial and error:

vim_cv_memcpy_handles_overlap=no \
vim_cv_bcopy_handles_overlap=no \
vim_cv_memmove_handles_overlap=no \
vim_cv_stat_ignores_slash=no \
vim_cv_getcwd_broken=no \
vim_cv_tty_group=world \
vim_cv_terminfo=yes \
LDFLAGS="-L/path/to/ncurses-5.7/lib" \
CFLAGS="-I/path/to/ncurses-5.7/lib" \
vim_cv_toupper_broken=no \
CC=agcc.pl \
./configure --host=arm-eabi --with-tlib=ncurses

I got this error message: "could not compile program using uint32_t", and manually patched the configure script because I couldn't remember how to regenerate the script from the configure.in:
$as_echo_n "checking uint32_t is 32 bits... " >&6; }
if test "$cross_compiling" = yes; then :
  true
#  as_fn_error "could not compile program using uint32_t." "$LINENO" 5
else

I also got an "undefined reference to sysinfo" error due to an android bug that omitted the sysinfo() call. So I commented out the HAVE_SYSINFO and HAVE_SYSINFO_MEM_UNIT lines in src/auto/config.h.

I think that was it! Once it finished compiling, I copied over the runtime/ directory and the src/vim binary to /data/vim on my phone. I did an "export VIMRUNTIME=/data/vim/runtime", and vim worked great!

Once I got my VIMRUNTIME set, I was able to ":syntax on", although I'm not getting any color. But otherwise it seems to work great!

You can find a tarball of vim for android on the Downloads page: look for vim-7.3-android-binary.tar.gz. There's also a tarred-up copy of my build directory, although I'm not sure why anyone would want that.

17 comments:

Unknown said...

very cool :)

Android said...

I've been running the Vanilladroid firmware for my HTC Eris for a few weeks now. Beside the phone spontaneously rebooting itself every few hours, its run great, and with built in wifi tethering.

JVR said...

hi

just what i needed! but... how do you start it? : from terminal:

./vim

permission denied

chmod u+x vim

bad mode

?? (i tried in su mode)

JVR said...

ps i'm using a samsung galaxy i9000, rooted

Anonymous said...

Some of the filesystems, including /sdcard, are mounted with a flag that disallows executing anything from it. Try /data

Anonymous said...

If this one doesn't work for you, try http://gdr.geekhood.net/gdrwpl/vim-android.php

Gary Danko said...

How did you get syntax highlighting to work? I am trying to build from source myself.

Anonymous said...

Sorry, I don't remember.

Interarticle said...

Heres how you turn on syntax highlighting (including all colors):
First in your terminal, "export TERM=xterm-color". This also enables jogball in vim.
Then open your .vimrc file (I used the vimrc_example.vim), and add the following code:
"------------------------
if &term =~ "xterm"
if has("terminfo")
set t_Co=8
set t_Sf=^[[3%p1%dm
set t_Sb=^[[4%p1%dm
else
set t_Co=8
set t_Sf=^[[3%dm
set t_Sb=^[[4%dm
endif
endif
"---------------
** Whereas "^[" must be typed as Control-V Esc **

Better place the above code before the part of code that turned syntax on, so that you won't need to turn it on again.

Interarticle said...

I've also got the multi-byte feature running, see: http://interarticle.blogspot.com/2011/01/native-vim-for-android-with-mbyte-and.html

Anonymous said...

hi i have few questions.
how i can do the same by putting the same vim code in mydroid source. meaning i don't want to write Android.mk files.
how i can do the above without exporting ndk and sdk paths.
please help me how to do it with help of agcc.pl by putting it in mydroid.

Anonymous said...

I think this is a bit broken, it doesn't read the ~/.vimrc file. Looks like it's trying to open "$HOME/.vimrc" literally instead of expanding $HOME into a useable path.

Tried compiling it myself from the 7.3 final release and it does the same thing.

kitsu said...

This is working really well for me!
I'm using ConnectBot as local terminal and running bash as a post-login command (found bash on XDA iirc). I run it as bash "-rcfile /sdcard/bashrc" so I can set some environment variables.

In my bashrc I'm exporting:
HOME=/sdcard/home
TERM=xterm-color
TERMINFO=/system/etc/terminfo
VIMRUNTIME=/system/usr/vim/runtime

I stole the terminfo from somewhere else, I don't know if it matters where you find it?

From there add a pretty standard .vimrc in ~/ and everything seems to work!

inVader said...

Very cool, indeed, this is way better than any texteditor you can download from the market since I'm very familiar with vim anyway.

However, after managing to get colored highlighting thanks to the previous posts I still have an unresolved issue.

When closing, vim tries to write to ~/.viminfo (home is /sdcard/home). When it does so for the first time, it creates .viminfo belonging to root:root with 664 permissions. On every consecutive time, I get a "cannot write error" due to permissions. Even if I change them to 666 manually, they are reset to 664 once vim closes the next time.

Any clues?

theGanymedes said...
This comment has been removed by the author.
theGanymedes said...

I also compiled it, but I compiled GlibC and Ncurses (with Glibc) as well, to allow dynamical linking of those libraries. The thread is available at http://forum.xda-developers.com/showthread.php?t=1299962 address.

Mine makes color highlight work either :)

Anonymous said...

I am developing application similar to Music Player. I am using Mediaplayer in android. I am unable get those effects please help me on this .... Actually I want to create an equalizer from which I can change the reverb & tone values of music, which Media Player is playing.But I am not getting any way to do it.


I have tried with EnvironmentalReverb and PresetReverb and even though I have tried Android NDK native audio app but I am not able to set the reverb effect.......Please help me I am stuck at this point