Skip to main content

Convert CSS or Scss to Sass in Vim

When I copy/paste some CSS or Scss into my .sass using projects it's annoying to have to clean up all the extra syntax. I've got this bit of regex on hand in Vim that makes it much easier.

:%s/}\| {\|;//g

Or, if you want to nuke new lines after a closing } as well you can use:

:%s/}\n\| {\|;//g

Here's the regex as a simple railroad diagram (via regexplained).

Created with Raphaël 2.1.0"}"" {"";"

This is not a “true” conversion from CSS to Sass, but at least it gets all the extra syntax out of the way so you can start moving stuff around!

By the way, I have nothing against .scss or .css, I just prefer .sass.