Vim YAML Compiler Plugin
Plagger とか、Catalyst とか Rails とかで YAML を書くことが多くなったので、ちょっと前に作ってみた。
これを ~/.vim/compiler/yaml.vim に作っておくと、:make → :cw でエラーチェック、修正が出来る。
とは言うものの、かなり無理やり。
if exists("current_compiler")
finish
endif
let current_compiler = "yaml"
let s:savecpo = &cpo
set cpo&vim
if exists(":CompilerSet") != 2 " older Vim always used :setlocal
command -nargs=* CompilerSet setlocal <args>
endif
CompilerSet makeprg=perl\ -MYAML\ -e\ '$f=shift\ or\ die\ qq/No\ input\ file.\\n/;eval{YAML::LoadFile($f)};if($@){warn\ qq/$@$f\ had\ compilation\ errors.\\n/}else{warn\ qq/$f\ syntax\ OK\\n/}'\ %
CompilerSet errorformat=
\%EYAML\ Error:\ %m,
\%C\ \ \ Code:\ %t,
\%C\ \ \ Line:\ %l,
\%C\ \ \ Document:\ %c,
\%-G\ at\ %.%#,
\%C%f\ had\ compilation\ errors.,
\%-G%.%#syntax\ OK,
\%Z,%-C%.%#
let &cpo = s:savecpo
unlet s:savecpoerrorformat が かなりひどいな・・・
よくわからんけどこれで動いてるっぽいのでそっとしておこう。
あとは ~/.vimrc に
autocmd FileType yaml set ts=4 sw=2 sts=2 autocmd FileType yaml compiler yaml
とか書いておけばOK