Find and replace with a new line in Visual Studio Code

I am testing a new Microsoft Visual Studio code editor in a Linux Fedora environment. I would like to know how to replace a new line (\ n) instead 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 a regular expression pattern and find "> <" and replace it with "> \ n <" How do I do this in Visual Studio code?

+185
visual-studio-code
May 20 '15 at 13:43
source share
6 answers

Update: In accordance with the release notes, this was added in version 0.10.6

In regex mode:

  • Now you can find ^, $ or ^ $ thanks to community input.
  • Now you can replace it with \ n or \ t.

enter image description here

Remember to check the regex switch (the rightmost icon).




Old answer: It seems that this is not possible in the current version (0.3.0) of VScode. The replace (ctrl + h) function seems to interpret \ n as text, not a new line.

I am sure this will be fixed in a quick release.

+255
Jun 11 '15 at 8:46
source share

In VS Code Release 1.30, you can type Shift + Enter in the search field to add a newline character without the need for regex mode.

enter image description here

Starting with version 1.3 of the VS code, regular expression search supports newline characters. To use this function, set the search box to regex mode and use \n as the newline character.

Multiline find in VS Code gif

+70
Jul 08 '16 at 0:25
source share

In version 1.1.1:

  • Ctrl + H
  • Check the regular export icon .*
  • Search: ><
  • Replace: >\n<
+44
May 27 '16 at 8:26
source share

A possible workaround would be to use multipoint. select> <part of your example use Ctrl + Shift + L or select all occurrences. Then use the arrow keys to move all the cursors between the tags and press Enter to insert a new line everywhere.

This will not work in all situations.

You can also use Ctrl + D to select the next match, which adds the next match to the selection and adds the cursor. And use Ctrl + K Ctrl + D to skip the selection.

+11
Jul 14 '15 at 12:08
source share

Also note that after clicking on the regexp icon to actually replace the text "\ n" with a new line, I had to use two backslashes before n as a search and "\ n" as a replacement.

(This will not allow me \ to use two backslashes in this post ... :)

+5
Apr 18 '17 at 22:55
source share

In my version of VS Code for Mac, I select the section and then the cntl + j key combination to remove line breaks.

+4
Jan 23 '18 at 18:57
source share



All Articles