Filed under Development
Replacing Newlines in Vim Searches
While trying to get a clearer view of a line of text with 5 million characters in it, I ran into some nuances in Vim’s search and replace.
The main issue was that replaceing the search string with a newline character – \n wasn’t visually creating a new line in the Vim buffer.
I found what I was looking for in this StackOverflow question: How to replace a character by a newline in Vim?
The general idea is to replace the search string with a \r as opposed to an \n.
For my use case, I was trying to break apart a really long HTML string along its <br> tags. So something along the lines of this:
:s/\<br>/\<br>\\r/g
Will search for <br> and replace it with a <br> and a visual newline.