Vim - HTML5とActionScript3のSyntax

syntax ファイルをインストールすると、ファイルの拡張子によってシンタックスに色がついて見やすくなる。

HTML5

今はHTML4までのsyntaxがデフォルトになっているけど、とりあえずいれておいて損はないと思う。

ここから html.vim をダウンロードして、.vim/syntax 以下に配置。
自分はなんだかデフォルトの html.vim が上書きされちゃうんじゃないかなーと思って、グローバルの設定ファイルを直に変更した。

$sudo vi /usr/share/vim/vim72/syntax/html.vim

" HTML 5 tags
syn keyword htmlTagName contained article aside audio bb canvas command datagrid
syn keyword htmlTagName contained datalist details dialog embed figure footer
syn keyword htmlTagName contained header hgroup keygen mark meter nav output
syn keyword htmlTagName contained progress time ruby rt rp section time video
syn keyword htmlTagName contained source figcaption

" HTML 5 arguments
syn keyword htmlArg contained autofocus autocomplete placeholder min max step
syn keyword htmlArg contained contenteditable contextmenu draggable hidden item
syn keyword htmlArg contained itemprop list sandbox subject spellcheck
syn keyword htmlArg contained novalidate seamless pattern formtarget manifest
syn keyword htmlArg contained formaction formenctype formmethod formnovalidate
syn keyword htmlArg contained sizes scoped async reversed sandbox srcdoc
syn keyword htmlArg contained hidden role
syn match   htmlArg "\<\(aria-[\-a-zA-Z0-9_]\+\)=" contained
syn match   htmlArg contained "\s*data-[-a-zA-Z0-9_]\+"

を追記。

さらに、上のURLにある通り、indent も変更するといいよ!と書かれているので

$sudo vi /usr/share/vim/vim72/indent/html.vim

call <SID>HtmlIndentPush('article')
call <SID>HtmlIndentPush('aside')
call <SID>HtmlIndentPush('audio')
call <SID>HtmlIndentPush('canvas')
call <SID>HtmlIndentPush('details')
call <SID>HtmlIndentPush('figcaption')
call <SID>HtmlIndentPush('figure')
call <SID>HtmlIndentPush('footer')
call <SID>HtmlIndentPush('header')
call <SID>HtmlIndentPush('hgroup')
call <SID>HtmlIndentPush('mark')
call <SID>HtmlIndentPush('menu')
call <SID>HtmlIndentPush('meter')
call <SID>HtmlIndentPush('nav')
call <SID>HtmlIndentPush('output')
call <SID>HtmlIndentPush('progress')
call <SID>HtmlIndentPush('section')
call <SID>HtmlIndentPush('summary')
call <SID>HtmlIndentPush('time')
call <SID>HtmlIndentPush('video')

を追記。

ActionScript

下記からmxml_as3.zipをダウンロード

解凍すると actionscript.vimmxml.vim があるので、それを

~/.vim/syntax/

以下に配置。
なんか mxml.vim が同じディレクトリの dtd.vim を参照しているっぽくてエラーを吐くのでコピーしておく

$cd ~/.vim/syntax
$sudo cp /usr/share/vim/vim72/syntax/dtd.vim ./

.vimrcに下記を追記

autocmd BufRead *.as set filetype=actionscript 
autocmd BufRead *.mxml set filetype=mxml

これを書くことで as 拡張子だったら filetype が actionscriptmxml 拡張子だったら mxml と認識してくれるようになる。これを書かない場合は、vi で開いたときに

:set ft=actionscript

とか書けば適用される。

かなり快適。