'Replace line breaks
I am using visual studio code for several things. Everything is working fine, but I cannot get one specific thing to work.
I need the ability to remove line breaks from the text.
Example:
first line
second line
Should become:
first linesecondline
Since a recent update it is possible to search for line breaks with using ^$. It is described here: https://github.com/Microsoft/vscode/pull/314
The problem I have is that when I use this for replacing, it does actually "add" to the line break and does not "replace" it.
Solution 1:[1]
I found that (at least on Windows) the solution was to use search and replace with a regular expression. Search for $\n and replace with nothing to get rid of the newlines. Note that the newline character that we want to replace is placed after the end of line matcher ($).
Solution 2:[2]
The latest version of VS Code has a shortcut to remove breaks from selection (CTRL + J).
Solution 3:[3]
@tripleonard hint did not work for me (no shortcut key assigned), so what I did was first ctrl+shift+p to list all commands and then just type Join lines
Solution 4:[4]
I'm able to manage this with the search and replace tool and "Use Regular Expression" enabled. Search for the pattern \n$ and replace with $
Solution 5:[5]
In my case shorcut in VS Code was not set. It took me a while to find out what command in VS Code am I looking for. For other with same problem it is: "Join lines".
Solution 6:[6]
Select the new line, and press ctrl+D (and hold it). Then press ctrl+h, you will be able to replace it with whatever you need.
Solution 7:[7]
Torn on regex mode and find and replace.
\n and replace with nothing
Solution 8:[8]
On Mac, use cmd+a to select all lines. Then, use cmd+shift+p to open commands and type Join Line and click on it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
