13

Often I find that I copy text from a gedit (linux) text editor document into a word processor like LibreOffice Writer. Of course I have hard linebreaks coded into the text.

How can I do a search and replace to reflow the text in LibreOffice Writer? In other words, I need the linebreaks removed.

Edit: Since it was suggested, I will add that I did tick regular expressions and being an old programmer I did use \n just in case it has any meaning for LibreOffice. The search key was not found when I opted for the find-and-replace.

Markus
  • 121
H2ONaCl
  • 1,458
  • 4
  • 22
  • 36

4 Answers4

11
  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.
jokerdino
  • 2,465
4

The answer you are looking for is to do find and replace, find $ and then replace with 1 blank space

Anon
  • 41
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).

LukeJKendall
  • 141
  • 1
  • 5
1

From https://help.libreoffice.org:

Use the AutoCorrect feature to remove line breaks that occur within sentences. Unwanted line breaks can occur when you copy text from another source and paste it into a text document. Note Icon

NOTE ->This AutoCorrect feature only works on text that is formatted with the "Default" paragraph style. <-

  1. Choose Tools - AutoCorrect - AutoCorrect Options.

  2. On the Options tab, ensure that Combine single line paragraphs if length greater than 50% is selected. To change the minimum percentage for the line length, double-click the option in the list, and then enter a new percentage.

  3. Click OK.

  4. Select the text containing the line breaks that you want to remove.

  5. In the Apply Style box on the Formatting bar, choose “Default”.

  6. Choose Tools - AutoCorrect - Apply.