Programming is a wonderful mix of art and science; source code is both a poem and a math problem. It should be as simple and elegant as it is functional and fast. This blog is about that (along with whatever else I feel like writing about).

Saturday, January 05, 2008

Flex: MXML Highlighting in VIM

For the first couple of weeks I've been using Flex, I've had to do it without syntax highlighting. My editor of choice is vim, which doesn't support MXML and ActionScript out of the box. However, syntax highlighting is a great invention, and now that I'm in the middle of a sizable Flex project, I figured I needed to get my hands on some syntax highlighting. (It'll be a whole lot cheaper than buying Flex Builder 2!)

The first thing you need to do is download the following two files:
actionscript.vim
mxml.vim

(Even if you only plan on editing MXML files, you need both of these. The MXML syntax depends on the ActionScript syntax, because MXML files can include ActionScript code.)

(Thanks to Abdul Qabiz for these files.)

You need to put these files into vim's syntax folder. On Ubuntu 7.10, it's /usr/share/vim71/syntax. (Make sure you install vim-full, using sudo aptitude install vim-full ... for some reason my installation of Ubuntu came with vim-tiny, which doesn't support syntax highlighting.)

Once that's done, you need to make sure the following lines are in your ~/.vimrc file:

au BufNewFile,BufRead *.mxml set filetype=mxml
au BufNewFile,BufRead *.as set filetype=actionscript
syntax on

Now ... the next time you open up an mxml file in vim, it'll have syntax highlighting for you. Excellent. My development environment just got a little bit better.

13 comments:

Anonymous said...

Thanks so much! This is awesomely useful!

Tim Wu said...

Thanks for such useful information. Anybody know where to find a vim syntax file for .hx(haxe source)?

Anonymous said...

really useful!!! Thanks

Anonymous said...

vim-full (aka. vim-gnome) isn't needed, the vim/vim-nox package (providing vim.basic) or any other vim-* variant dependent on vim-runtime is enough. It should only be vim-tiny that doesn't support syntax highlighting.

The new thing is that a variant of vim is included in the basic installation, where you previously would have to get along with nano, until you got vim installed. The 5.4 MiB vim-runtime dependency makes a non-crippled variant of vim too big to be included in the base installation.

Sean Schulte said...

@asbjorn.it:

Thanks for the clarification!

I definitely like having vim available immediately after the install, but didn't know the details behind vim-tiny.

Tristan Webb said...

Thanks for the guide

ronnieotts said...

SWEET!

Anonymous said...

It works very well in mxml file with embedded actionscript functions.
However, when I indent above mxml file (gg=G), the mxml parts indented well but the actionscript funtions code did not being indented at all.
Does anyone as same as me?
If indent well, this is perfect :)
Could anyone tell me how can I indent mxml file with embedded actionscript code?
thanks and regards

Jamal said...

When I installed the syntax files, I also had to get dtd.vim because it was being referenced from one of these. I just used this one:

http://vim.cybermirror.org/patches/dtd.vim

Anonymous said...

Very helpful! Thank you!

JA said...

Just what I needed. Thanks.

avejidah said...

Dankee.

Anonymous said...

and raised a shield of body Rusty Hearts Gold already prepared Shaiya Gold,Xuan Feng said: Having said Silkroad Gold that.scared to d SWG Credits o was looking like paper Swtor Credits,pressing a big step forward Tera Gold,why is over several days Tibia Money,plea se give weekend Vindictus Gold,there are more than WOW MONEY a decade behind bit WOW GOLD his bro ther Eden Eternal Gold - Age of Empires GOLD Age of Empires GOLD
,enough to accommodate Metin2 Yang tens of thousands of people,straight as Nostale Gold the road ancient poem A Thousand Perfect World Gold grinding million R2 Gold hit Kennedy also strong Rappelz Rupees,together with the maid Rift Gold standing on both sides of the Church Rift Plat,will have the whole world ROM Gold,The battle front on the big screen Runescape Money displaynno