如何使vim按字母顺序在一行内排序CSS规则? [英] How to make vim alphabetically sort CSS rules within a single line?

查看:190
本文介绍了如何使vim按字母顺序在一行内排序CSS规则?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

资料来源:

  .foo {line-height:150px; font-size:24px;清除: } 



结果:

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

你对vim的魔法部分有什么建议?

解决方案

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

拆分 {; 将每个规则分成单独的行,:sort CSS定义),然后将它们连接在一起。


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?

解决方案

: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.

这篇关于如何使vim按字母顺序在一行内排序CSS规则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆