Google Docs – How to Paste Source Code Without Creating New Paragraphs

google docs

When I paste source code in Google docs document, every line of the source is on a new paragraph. That creates unnatural spacing between lines.

I can manually fix this by tediously removing each paragraph and then inserting new line with Shift+Enter. But is there a way to avoid having bunch of paragraphs for every new line?

Best Answer

It sounds as though formatting is being carried over from your source code editor. If you don't mind removing all formatting (such as colors & fonts), this is what I've done on a PC:

  1. Copy the source code.
  2. Paste it into Notepad, which has no formatting features. It will strip away all existing formatting.
  3. "Select All" in Notepad, and copy the text.
  4. Paste that into the Google Document.

There is probably a similar Mac program that will strip away formatting, if you need it.