omoonのブログ

旅の思い出を写真とともに書いてみるか。

vimからcsstidyを使う

csstidyはcssを自動整形してくれるツール。perltidyのcss版ってとこか。
http://csstidy.sourceforge.net/

これを、vimから

:%! perltidy

ってperlでいつもやっているみたいに使いたい。


で、実は、
http://blog.hide-k.net/archives/2007/06/vimcsstidy.php

このページにすべてが書いてあるわけだが、自分用にもメモ。

:%! ~/bin/csstidy - --silent=true --template=low

こうする。
デフォルトだとインデントがなくなってしまって、人間には読みにくくなるため、

--template=low

としている。

このページのcssを一部抜粋。こんな感じにしてくれる。

h1
{
    display:none;
    line-height:0;
}

pre
{
    border:1px solid #ccc;
    background-color:#eee;
    overflow:auto;
    padding:8px;
}

blockquote
{
    border-left:5px solid #dde;
    padding-left:12px;
}

ところで、「tidy」って動詞でも使うんですね。知らなかった。

verb ( -dies, -died) [ trans. ] (often tidy someone/something up)
bring order to; arrange neatly : I'd better try to tidy my desk up a bit | figurative the bill is intended to tidy up the law on this matter | [ intrans. ] I'll just go and tidy up.

LeopardのNew Oxford American Dictionaryより。Leopardの辞書、めっちゃ便利。