Google-docs – How to prevent Google Docs from changing (some) spaces to tabs when pasting from text editor

google docs

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.

Best Answer

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.