auto indent in vim string replacement new line?

Posted by rxin on Stack Overflow See other posts from Stack Overflow or by rxin
Published on 2010-04-28T19:42:41Z Indexed on 2010/04/28 19:47 UTC
Read the original article Hit count: 278

Filed under:
|

I'm using the following command to auto replace some code (adding a new code segment after an existing segment)

%s/my_pattern/\0, \r some_other_text_i_want_to_insert/

The problem is that with the \r, some_other_text_i_want_to_insert gets inserted right after the new line:

mycode(
  some_random_text my_pattern
)

would become

mycode(
   some_random_text my_pattern
some_other_text_i_want_to_insert   <--- this line is NOT indented
)

instead of

mycode(
   some_random_text my_pattern
   some_other_text_i_want_to_insert  <--- this line is now indented
)

i.e. the new inserted line is not indented.

Is there any option in vim or trick that I can make the newly inserted line indented?

Thanks.

© Stack Overflow or respective owner

Related posts about vim

Related posts about regular-expressions