Skip to content

How to Merge Multiple Lines in Google Docs

Having broken lines is not uncommon when editing documents in word processors like MS Word and Google Docs. The most common cause behind the separated lines is usually from copying and pasting text from sources in a different format.

Regardless, pasting the content without formatting (i.e. in plain text) is not guaranteed to help this situation other than remove any text formatting applied to the source (e.g. fonts, italics or bold).

So how does one combine the multiple lines without resorting to time-consuming manual edits? Well, the answer lies in the Find and Replace function which thankfully Google Docs includes, albeit less robust to the MS Word variant.

The principle behind this is to find all the line breaks and replace them with nothing. This will remove all empty new lines, and therefore merge the lines of text into one block.

Removing Line Breaks in Google Docs using Regular Expression

Now, in Word this is very easy to do as all you have to do is find all the paragraph marks using ^p in the affected lines and replace them with nothing.

With Google Docs, however, things are a bit more complicated: while it does support paragraph marks, you cannot use them in the Find and Replace dialog. Instead, you have to use regular expression.

The Regex equivalent for matching a line break is \n. We can use this to match all new lines and merge the lines as follows:

  1. Go to Edit > Find and Replace, or just press Ctrl+H.
  2. In the Find and Replace box, enable the option Match using Regular Expressions.
  3. In the Find box, enter \n and leave the Replace box empty. All the new lines in the document will become highlighted.
    A screenshot showing the Find and Replace box in Google Docs
  4. Click the Replace All button to remove all the line breaks.

This will combine all the multiple lines in the entire document, irrespective of how they’re formatted. This includes any titles and headings which, ideally, we don’t want to merge with the preceding text.

Selective Replacement

In Word, this can be done simply by selecting the affected lines before using Find and Replace. Google Docs however ignores any selected content and instead searches the whole document.

Due to this limitation, we can use one of the following workarounds:

  • Individually replace the line breaks by using the Next button to skip over specific line breaks as shown in the video tutorial.
  • Copy the affected lines into a new blank document. Merge the lines from there, then paste the merged lines into the original document.
  • Use a regular expression that only matches the affected lines.

The first two options are preferable, however they’re only practical when working with small documents. For large documents, using a suitable regex is a far more ideal solution to save time.

Here are some few expressions you can try:

  1. \n: Matches all line breaks
  2. \n\n: Matches all double line breaks
  3. \n\n\n: Matches three consecutive line breaks
  4. \r?\n(?!\r?\n): Matches only single line breaks. Titles and headings are usually followed by two or more line breaks, so this will skip them.
Share:

Leave a Reply

Feel free to share your comments or questions with me. I may not be able to respond immediately so please check later once I've approved your comment.

Your email address will not be published. Required fields are marked *

Kelvin Kathia

Kelvin Kathia is a writer that's passionate about sharing solutions to everyday tech problems. He's the founder and editor of Journey Bytes, a tech blog and web design agency. Feel free to leave him comments or questions regarding this post, or by leaving him a message on the contact page. If you found his content helpful, a donation is much appreciated.