vim search for ) replace with text then newline then )


I have a huge sql query with 574 lines and I needed to replace a closing bracket ) with text and then a new line with a closing bracket


) AS


GROUP BY v.visit_id
) AS


Using vim’s search and replace feature

:%s/^)/GROUP BY v.visit_id\r)/gc

The above searches for the lines beginning with the closing bracket ) and then replaces it with text and then new line (\r) followed by a closing bracket )


How to replace a character by a newline in Vim

Add a newline after given patterns

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s