Automatically removing linebreaks in LibreOffice Writer

Solution 1:

  1. In the Edit > Find and Replace dialog, tick "Use regular expressions", put "\n" in the 'search for' box, nothing in the replace with box, click Replace all. This removes line breaks that you can insert with Shift+Enter (manual line breaks). Here's a link to LibreOffice documentation on regular expressions.
  2. LibreOffice Writer can't replace paragraph breaks by default. Use the AltSearch add-on for OpenOffice, as it also works with LibreOffice.
  3. To do the paste-and-remove-linebreaks automatically, you can try recording a macro (help.libreoffice.org/Common/Macro), just paste and perform the replace and have LibreOffice record them in a macro.

Solution 2:

Realising that \n in the search and \n in the replacement part mean different things is helpful to know.

\n in the search matches "hard returns" - what you get if you type Ctrl-Enter.

\n in the replacement means "end of paragraph".

In my case, I was struggling to replace lines where the visible paragraphs were all in fact just one paragraph with blank lines encoded as two "hard returns". This became obvious by turning on visibility of non-printing characters in the View menu.

So in my case, since my paras were like this (denoting "hard return as {ent}" and end of para as {eop}):

Para1{ent}{ent}Para2{ent}{ent}Para3{eop}

So a Find all then a Replace All of:

\n\n

by

\n

(with regexp turned on), changed that to:

Para1{eop}Para2{eop}Para3{eop}

It may also help to know that you can search for an extra empty paragraph by searching for $^ (actually, ^$, too).