0
/* Comments for code... */

if (...) {

}

我需要删除评论和之间的空白行if

/* Comments for code... */
if (...) {

}

我目前正在使用以下正则表达式:

/\*\/\ze\n^$\n[ ]*if
  • \*//: 评论结束 ( */)
  • ^$: 前空行if
  • [ ]*if: 空格和一个if

在我使用\ze时,光标最终指向*/. 我应该怎么做?

4

3 回答 3

2

试试这一行:

%s#\*/[\s\r\n]*#*/\r#

它会让

/* Comments for code... */





if (...) {

}
/* Comments for code... */






else{


}

进入:

/* Comments for code... */
if (...) {

}
/* Comments for code... */
else{


}
于 2013-04-11T12:03:04.450 回答
1

为什么不也使用\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)
于 2013-04-11T10:36:12.917 回答
1
:g+*/+j

更快,但可能太宽泛了。

您可以执行以下操作:

:g+*/\_\s*if+j
于 2013-04-11T11:57:47.240 回答