15

What's worse is that in some cases it behaves as if it gets rid of the 4 spaces instead of replacing with a tab. This does horrible things to any ASCII diagrams appearing in code.

Ex: take the following and paste it into a text editor like notepad++ then copy/paste into google docs (it will be formatted correctly if you paste it directly in):

else if(xp>=Width){
    if(yp<0){
        xb=Width;
        yb=0;
    }
    else if(y>Height){
        xb=Width;
        yb=Height;
    }
}

will end up looking like:

else if(xp>=Width){
    if(yp<0){
    xb=Width;
    yb=0;
    }
    else if(y>Height){
    xb=Width;
    yb=Height;
    }
}

and if you move the cursor around, it behaves like there is a tab in front of each inner if/else and 5 spaces in front of xb=Width, etc.

Edit: in the current version of google docs, using the "paste without formatting" and "remove formatting from selected text" options together are effective for getting code INTO google docs, though it still replaces tabs with spaces when you past FROM google docs.

4
  • Not sure, but could this work? webapps.stackexchange.com/a/58153/21583 Jun 1, 2017 at 8:47
  • I pasted it into Atom then Google Docs, and using both Ctrl-V and Ctrl-Shift-V, I was able to have it come out perfectly in Google. Could be an issue with the particular text editor, browser, or combination of the two?
    – Peter
    Jun 9, 2017 at 5:36
  • 1
    I've tried this from multiple text editors in both windows 10 and Ubuntu, with Firefox, Chrome, Chromium, and even Internet Explorer. Not only does it sometimes replace tabs with spaces and/or spaces with tabs, but it doesn't seem to do either of these with any sort of pattern I've been able to discern so I can't even write a script to do the translation. Could you let me know which OS & browser you were using? Nov 15, 2017 at 1:02
  • I am using VSCode (version 1.43). When I use Copy and Paste from VS Code to Google docs it preserves tabs or spaces. However, it includes the VSCode theme (black background etc). If I then use Google docs "clear formatting" the layout is changed. The same thing happens if I try Paste without formatting in Shift+Ctrl+V. I'm using Windows 10.
    – JohnC
    Apr 8, 2020 at 19:28

2 Answers 2

11

Neither ctrl+V nor control+shift+V worked for me - both pasted spaces as tabs. However, I tried find and replace, checked with regular expressions, and changed \t into four spaces. My example then lined up correctly.

1
  • Too bad Google slides do not have find/replace with regex (but do convert some spaces to tabs) Jul 26, 2021 at 16:57
1

This works for me:

Open a plain text editor that supports dragging selected text to another application.

First paste the text into that editor, select it, and drag into the desired location in the Google doc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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