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?
This question is related to
visual-studio-code
With VS Code release 1.38 you can press CTRL + Enter in the editor find box to add a newline character.
With VS Code release 1.30 you can type Shift
+ Enter
in the search box to add a newline character without needing to use regex mode.
Since VS Code release 1.3, the regex find has supported newline characters. To use this feature set the find window to regex mode and use \n
as the newline character.
A possible workaround would be to use the multi-cursor. select the >< 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 newline everywhere.
This won't work in all situations.
You can also use Ctrl+D for select next match, which adds the next match to the selection and adds a cursor. And use Ctrl+K Ctrl+D to skip a selection.
with v1.31.1 in RegEx mode the Replace All functionality is broken. clicking that button replaces only one instance
CTRL + H, then select regex (*) and write \n
Shorter version: CTRL+H ALT+R \n
Also note, after hitting the regex icon, to actually replace \n
text with a newline, I had to use \\n
as search and \n
as replace.
In version 1.1.1:
.*
><
>\n<
On my mac version of VS Code, I select the section, then the shortcut is Ctrl+j to remove line breaks.
Source: Stackoverflow.com