Reputation: 77298
I want to alphabetize css selectors (and properties) in my scss files. I'm sure vim can do this (even if I need to use some external tool). How would you sort the following?
h2 {
color:red;
background-color:green;
}
h1 {
font-size:12px;
}
To this:
h1 {
font-size:12px;
}
h2 {
background-color:green;
color:red;
}
Upvotes: 2
Views: 1344
Reputation: 19803
Try CSScomb. This tool sorts your css in cusomizable way. You can try it online.
CSScomb has plugin for Vim.
From the CSScomb's site:
Upvotes: 0
Reputation: 40927
For your simple example the following two snippets seem to work, however I fear they may fall down with larger, more complex css.
To order the properties I used a macro**:
:let @q = "/{^Mvi{:sort^M"|%norm! @q
** Note that the ^M's here are entered with Ctrl-vCtrl-m.
Explanation:
To order the selectors I used substitute and sort:
:%s/\v([^}])\n/\1/g|%sort|%s/\v[;{]/&\r/g
Explanation:
Trailing whitespace throws this off a bit but you don't have any of that, right? :)
Upvotes: 5