/* Comments for code... */
if (...) {
}
我需要删除评论和之间的空白行if:
/* Comments for code... */
if (...) {
}
我目前正在使用以下正则表达式:
/\*\/\ze\n^$\n[ ]*if
\*//: 评论结束 (*/)^$: 前空行if[ ]*if: 空格和一个if
在我使用\ze时,光标最终指向*/. 我应该怎么做?
/* 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