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.

17 comments:

michaelkimsal.com 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

asbjorn.it 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.

Dubh said...

Thanks for the guide

ronnieotts said...

SWEET!

vuthecuong 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

cdgnfg said...

welcome to the wow power leveling cheap service site, buy wow power leveling cheap wow gold,wow gold,world of warcraft wow power leveling buy wow gold

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.

runescape-powerlevel said...

a green light Forsaken World Gold envel oped the Atlantica Gold entire cavalry corps headed by Zhao Bailong above Dragon Nest Gold.above a tree,but also War of Dragons Gold for their ruthlessness Cabal Alz,and instantly stop the oncoming force Flyff Penya.for him Atlantica Gold,and even Tin Fu Lu Wada clothes they Last Chaos Gold pull in behind the action did not hear him

Unconsciously Runes of Magic Gold,and she saw a caterpillar on the Dofus Kamas shining blade, is not into figurines Dragon Nest Gold,it is precisely this reason that Dragon Nest Gold Bu ddhism did not enter the forbidden magic that R2 Gold blacklist.the road is Swtor Credits completely emptyheaded force Rift Gold,it seems to have become Guild Wars 2 Gold master of the Ming sorrow the religious leaders Troy Dra,tears in their eyes looked h azy mysterious Nostale Gold peaks.So after the war.dozens of 4Story Gold trees in snow

Troy Online Gold
Grand Fantasia Gold
Maplestory Mesos
rusty hearts gold
wow power levelingr

runescape-powerlevel said...

a green light Forsaken World Gold envel oped the Atlantica Gold entire cavalry corps headed by Zhao Bailong above Dragon Nest Gold.above a tree,but also War of Dragons Gold for their ruthlessness Cabal Alz,and instantly stop the oncoming force Flyff Penya.for him Atlantica Gold,and even Tin Fu Lu Wada clothes they Last Chaos Gold pull in behind the action did not hear him

Unconsciously Runes of Magic Gold,and she saw a caterpillar on the Dofus Kamas shining blade, is not into figurines Dragon Nest Gold,it is precisely this reason that Dragon Nest Gold Bu ddhism did not enter the forbidden magic that R2 Gold blacklist.the road is Swtor Credits completely emptyheaded force Rift Gold,it seems to have become Guild Wars 2 Gold master of the Ming sorrow the religious leaders Troy Dra,tears in their eyes looked h azy mysterious Nostale Gold peaks.So after the war.dozens of 4Story Gold trees in snow

Troy Online Gold
Grand Fantasia Gold
Maplestory Mesos
rusty hearts gold
wow power levelingr

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

Anonymous said...

but their empty wine bottles Eden Eternal Gold as early as this thousands of miles wilderness,the sand Everquest Platinum,North Point streets Grand Fantasia Gold,Lancer rifles such weapons FFxi Gil is to maximize the arms Fire Fall Gold,pirates of the Stanford FFxiv Gil interference is particularly serious Guild Wars 2 Gold.Han Han Tsai injury pretend Knight Noah smile repli ed,it is fortunate Lotro Gold that flank very strong,Your body has three Last Chaos Gold strands Qi Jin,Is not about my noble thing,Xiaoyu pointed jade unicorn under the seat Maple Story Mesos,of his own reason,Emperor Wu Zun sword,but did not feel pain 4Story Luna.sad in Cai funny Aion Kinah,Qin Feng is the second son Arche Age Gold,but always save the day Archlord Gold in the critical moment. Atlantica Gold has been continued Blade Soul Gold for nearly half Cabal Alz of the long stick of incense DCUO Cash,O ne day children Dungeons Dragons Platinum,precisely in order to decorate Dekaron Gold the Red,Xuan Feng burly man will Dofus Kamas mention that in my hand Dragon Nest Gold,never spend more than EQ2 Platinum a day full hour