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?

  • It may be worth mentioning where you are copying from; I tried to reproduce the problem and couldn't. – user135384 Jan 10 '17 at 18:15

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.

  • I will try that. I was convinced editor I use is 100% plaintext, but maybe not. – Tomáš Zato - Reinstate Monica Jan 10 '17 at 18:22
  • 2
    Be sure that in Notepad, "Word Wrap" is turned off. Word Wrap can give unpredictable results. (The option is in the Format menu.) – BrettFromLA Jan 10 '17 at 18:29
  • 2
    Note if you're pasting on Mac, the keyboard shortcut Cmd + Shift + Option + V in most applications has the action Paste without Formatting. As a frequent Docs user, I have this one burned into my muscle memory. – Craig Otis Jan 10 '17 at 22:15
  • Ok, this answer works in general, though in my particular document it doesn't work. I wonder if there's some kind of setting that alters the behavior. – Tomáš Zato - Reinstate Monica Jan 11 '17 at 14:29
  • I don't know of any fancy settings in Notepad. You may want to check the ASCII codes of line breaks that come from your source editor; they may not just be CHR(10) + CHR(13), so Google Docs may interpret them differently. If that's the case, you could replace the exotic line break characters with the standard line break characters and that should fix the issue. – BrettFromLA Jan 11 '17 at 19:30

If you add in shift to your paste command (e.g. shift-control-P, or shift-command-P depending on your operating system) then it will paste the text without any formatting. As it seems that the paragraphs are due to some extra formatting being added, this should fix that issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.