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

后端 未结 3 1886
别那么骄傲
别那么骄傲 2021-02-10 15:35

Source:

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

vim magic here, probably something visual selection based

R

3条回答
  •  一个人的身影
    2021-02-10 16:01

    Another one-liner:

    s/{\s*\zs.\{-}\ze\s*}/\=join(sort(split(submatch(0), '\s*;\s*')), '; ').';'
    

    This time we use sub-replace-\=, and list manipulation functions (sort(), split(), and join())

提交回复
热议问题