[英]Multiline regex pattern to delete blank lines
/* Comments for code... */
if (...) {
}
我需要删除注释和if
之间的空白行:
/* Comments for code... */
if (...) {
}
我目前正在使用以下正则表达式:
/\*\/\ze\n^$\n[ ]*if
\\*//
:注释结尾( */
) ^$
: if
之前的空白行 [ ]*if
:空格和if
当我使用\\ze
,光标最终指向*/
。 我应该怎么做?
试试这一行:
%s#\*/[\s\r\n]*#*/\r#
它将使
/* Comments for code... */
if (...) {
}
/* Comments for code... */
else{
}
成:
/* Comments for code... */
if (...) {
}
/* Comments for code... */
else{
}
为什么不也使用\\zs
。
这为我工作:
:%s/\*\/\zs\n*[ ]*\zeif/\r/g
阐释:
%s - substitution on the entire file
\*\/ - end of comment
\zs - start of match
\n*[ ]* - eol and spaces
\ze - end of match
if - followed by if
/\n/ - replacement
g - global regex (multiline)
:g+*/+j
速度更快,但可能范围太广。
您可以执行以下操作:
:g+*/\_\s*if+j
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.