vim search for ) replace with text then newline then )

Problem

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

Before:


) AS

After:


GROUP BY v.visit_id
) AS

Solution

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 )

References

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:

WordPress.com Logo

You are commenting using your WordPress.com 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