how to replace a single newline with a double newline in google docs

Viewed 115

My question is simple, what do I enter into find-and-replace on google docs so that I can replace a single newline with a double newline so that there is an empty space between my paragraphs? I already know that I can search \n with regular expressions on, but how can I set it to replace it with two?

1 Answers

Sadly, you can't do that in search and replace UI.

I'd recommend using Apps Script and using this code.

Code:

function addAdditionalNewLine() {
  DocumentApp.getActiveDocument()
    .getBody()
    .getParagraphs()
    .forEach(function (paragraph){
      paragraph.appendText("\n");
    });
}

function onOpen() {
  var ui = DocumentApp.getUi();
  // Or DocumentApp or FormApp.
  ui.createMenu('Custom Menu')
    .addItem('Add New Lines', 'addAdditionalNewLine')
    .addToUi();
}

Note:

  • What the code does is add a new line every end of every paragraph.
  • Additionally, I added a custom menu whenever the document is refreshed/opened (You may need to refresh the document after saving the script): output
  • Please make sure to have the necessary permissions first on the editor by running the function addAdditionalNewLine manually.

Sample:

sample

Output (after running clicking "Add New Lines" menu):

output1

Related