Find and replace with a newline in Visual Studio Code

Sriram picture Sriram · May 20, 2015 · Viewed 312k times · Source

I am trying out the new Microsoft Visual Studio Code editor in Linux Fedora environment. I would like to know how to replace new line (\n) in place of some other text.

For example, I have html text like this

<tag><tag> 

which I would like to replace as

<tag>
<tag>

In sublime I would use regex pattern and find "><" and replace with ">\n<" How do I accomplish this in Visual Studio Code?

Answer

H&#229;kon Egset Harnes picture Håkon Egset Harnes · Jun 11, 2015

In the local searchbox (ctrl + f) you can insert newlines by pressing ctrl + enter.

Image of multiline search in local search

If you use the global search (ctrl + shift + f) you can insert newlines by pressing shift + enter.

Image of multiline search in global search

If you want to search for multilines by the character literal, remember to check the rightmost regex icon.

Image of regex mode in search replace


In previous versions of Visual Studio code this was difficult or impossible. Older versions require you to use the regex mode, older versions yet did not support newline search whatsoever.