Reputation: 61
/* Comments for code... */
if (...) {
}
I need to delete the blank line between the comment and the if
:
/* Comments for code... */
if (...) {
}
I am currently using the following regex:
/\*\/\ze\n^$\n[ ]*if
\*//
: end of comment (*/
)^$
: blank line before if
[ ]*if
: spaces and an if
As I use \ze
, cursor finally points to */
. How should I do?
Upvotes: 0
Views: 322
Reputation: 378
The following regex can achieve this:
:%s/\(\/*\)\(\n\+\)\(if\)/\1\r\3
The \(\/*\)
match the comment line
\(\n\+\)
match any empty lines below till
\(if\)
that match if
line
Upvotes: 0
Reputation: 195059
try this line:
%s#\*/[\s\r\n]*#*/\r#
it will make
/* Comments for code... */
if (...) {
}
/* Comments for code... */
else{
}
into:
/* Comments for code... */
if (...) {
}
/* Comments for code... */
else{
}
Upvotes: 2
Reputation: 196546
:g+*/+j
is much quicker but probably too broad.
You could do something like the following:
:g+*/\_\s*if+j
Upvotes: 1
Reputation: 38543
Why not use \zs
as well.
This worked for me:
:%s/\*\/\zs\n*[ ]*\zeif/\r/g
Explaination:
%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)
Upvotes: 1