Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make vim alphabetically sort CSS rules within a single line?

Tags:

css

vim

sorting

Source:

.foo { line-height: 150px; font-size: 24px; clear: both; }

vim magic here, probably something visual selection based

Result:

.foo { clear: both; font-size: 24px; line-height: 150px; }

What do you suggest for the vim magic part?

like image 963
lkraav Avatar asked Jan 17 '23 15:01

lkraav


1 Answers

:s/\([{;]\)\s*/\1\r/g | '[+1,']sort | '[,']join

Split the line on { or ; to get each rule into a separate line, :sort them (omitting the first line containing the CSS definition), then join them back together.

like image 144
Ingo Karkat Avatar answered Jan 31 '23 02:01

Ingo Karkat