I want to replace if (condition) //comment \n\s*{
(\n - newline, \s* 0 or more whitespaces), or rather restructure it, so brace is on same line as if and comment is moved to next one and is indented by one tab more.
It's a Vim practice task, so please don't give me whole solution, instead help me understand what I'm missing.
My regex works and catches what I want (starting with comment on purpose):
:%s#\(//\)\(.\)*\n\(\s\)*{#{\r\t\3\1 \2#g
My replace pattern however doesn't catch groups, using \1 \2 \3
doesn't work. To be more precise, only \1
works.
I get a brace, a new line, one more indent as wanted, then groups (except for \1
(meaning //
) are NOT there:
if (condition) {
//
No comment text, no tabs/whitespaces aside from one I specifically put there. What am I missing?
\n
and\s
mean? Are they literal characters or used as their original meaning?\n
and\s
are newlines and space characters, as his given regex won't match otherwise.. from what I could make out,(.\)*\n
should be(.*\)\n
//
" into a group, because you could just put//
on the other side, rather than\1