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:

The latest version of VS Code has a shortcut to remove breaks from selection (CTRL + J).

Solution 2:

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 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