views:

169

answers:

1

In TextMate there is this awesome option to "Format CSS" and "Format CSS Compressed". This option doesn't seem to exist in vim. Perhaps it's in a plugin I'm not aware of? Or maybe I need to integrate CSS Tidy somehow?

+5  A: 

You can integrate CSS Tidy fairly easily. Since you're coming from TextMate I'll assume you're on a Mac. If you don't already have CSS tidy installed, I'd recommend installing it via a package manager, like the excellent Homebrew.

Once it's installed, you can allow Vim to use CSS tidy for the = command, which automatically formats code, by adding the following to your ~/.vimrc:

autocmd filetype css setlocal equalprg=csstidy\ -\ --silent=true 

Now whenever you have a CSS file open, it will consult CSS Tidy to format it when you invoke the = command. Try it on an open CSS file with gg=G to format the whole document.

Consult the CSS Tidy usage guide to add any other options you like, and don't forget to escape spaces you add to the above ~/.vimrc command with \.

michaelmichael