I have a text file with several lines that I want to join together (concatenate) in a text editor. I.e. without resorting to command line tools (especially on Windows where they might even not be available at all).

I am using Geany and its search and replace function with no success: tried replacing $ with nothing using (multiline) regex and \n with nothing using escape sequences.

Even multiline matching seems to replace only the content, leaving the (empty) lines as they are!

Is there any simple method for doing it?

  • do u just want to get rid of all the \n new lines and join all the lines as one single long line? – Prasanna Sep 21 '16 at 10:48
  • Yes, that's it. – a1an Sep 21 '16 at 10:53
  • I don't have geany installed. but looking at the manual tells me that if you find \n and replace with space - it should do the trick. Have u tried that? I also assume that you have checked the Use regular expressions checkbox in the find and replace dialog – Prasanna Sep 21 '16 at 10:55
  • Using vi, a simple uppercase J joins a line with the next one. It inserts a space character as a replacement of the line break. – mouviciel Sep 21 '16 at 11:03

Thanks to @Prasanna confirming that it should work with an "escape sequence based" replacement. I figured out it could be an issue with line termination and indeed replacing \n with a space puts a space at the beginning of each line!

So I guess it would be platform dependant but it should work according to the line ending in use:

On windows, search for


Replace with nothing (empty string) or a space character, depending on your needs.

Regular expression does not seem to do do the trick at all instead.


I've found the secret to joining lines in Geany via regex search and replace is to ensure Use multi-line matching is enabled. I love Geany, so here is the sequence of steps for removing line endings (Windows shown here, change the line ending escape characters as needed for *nix):

  • Verify your line endings: from the menu select View >> Show line Endings (e.g. on Windows this will show CRLF (\r\n)).
  • Highlight/Select the lines you want to join
  • CTRL-H (Replace)
  • In the Search for: field, enter \r\n
  • In the Replace with: field, enter nothing
  • Ensure Use regular expressions is checked
  • Ensure Use multi-line matching is checked
  • Click In Selection to join all lines in the selection (obviously this can also be done on the entire document or line-by-line as you desire).

It won't work without checking Use multi-line matching, so that is the secret tip.


Actually, there is a Join Lines command in Geany, but its kind of hidden: you have to go to Edit/Preferences/Keybindings Action: Format/Join Lines, and there you can assign a keyboard shortcut; as they say in Join lines failure #510:

Yes, "join lines" is not in a menu, thats bad because it makes it difficult to discover, and assigning a keybinding is not supposed to make it appear in the menu.

But if it is assigned a keybinding it works for me with ccec1fe.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.