使用vi,我如何使CSS规则成一个衬垫? [英] Using vi, how can I make CSS rules into one liners?

查看:112
本文介绍了使用vi,我如何使CSS规则成一个衬垫?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:

#main {
      padding:0;
      margin: 10px auto;
}

示例:

#main {padding:0;margin:10px auto;}

我有大量的CSS规则占用太多行。我不知道:%s / 命令要使用。

I have a ton of CSS rules that are taking up too many lines. And I cannot figure out the :%s/ commands to use.

推荐答案

p>这是一个单行:

:%s/{\_.\{-}}/\=substitute(submatch(0), '\n', '', 'g')/

\ _。匹配任何字符,包括换行符, \ { - } 版本 * ,因此 {\_.\ { - }} 匹配一对匹配的卷曲

\_. matches any character, including a newline, and \{-} is the non-greedy version of *, so {\_.\{-}} matches everything between a matching pair of curly braces, inclusive.

\ = 可以替换vim表达式的结果,使用从匹配的文本(在 submatch(0)中)删除所有换行符'\\\
'
substitute()函数。

The \= allows you to substitute the result of a vim expression, which we here use to strip out all the newlines '\n' from the matched text (in submatch(0)) using the substitute() function.

反向(将单行版本转换为多行)作为一个衬垫:

The inverse (converting the one-line version to multi-line) can also be done as a one liner:

:%s/{\_.\{-}}/\=substitute(submatch(0), '[{;]', '\0\r', 'g')/

这篇关于使用vi,我如何使CSS规则成一个衬垫?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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