6

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.

  • Not sure, but could this work? webapps.stackexchange.com/a/58153/21583 – Vidar S. Ramdal Jun 1 '17 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 '17 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? – Dustin Soodak Nov 15 '17 at 1:02
3

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.

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.