Achieving 2-space indentation in Google Docs for coding practice

I’m in a bit of a pickle. My teacher wants us to use Google Docs for coding practice instead of an IDE. I know it sounds weird, but that’s what we have to work with.

I’m used to 2-space indentation and really want to keep using it. Is there a quick way to do this in Google Docs? Maybe a shortcut or an add-on?

Here’s what I’m trying to do:

if (condition) {
  doSomething();
  if (anotherCondition) {
    doSomethingElse();
  }
}

Right now, when I hit enter, the cursor goes back to the start of the line. It’s frustrating to manually space everything. Any tips on how to make this easier?

I’d really appreciate any help or workarounds you can suggest!

As someone who’s had to code in unconventional environments, I feel your pain. Here’s a trick that’s saved me countless hours: create a template document with pre-formatted code blocks. Set up your indentation once, then copy-paste these blocks as needed.

Another lifesaver is using the ‘Find and Replace’ feature creatively. You can quickly add indentation to multiple lines by searching for ‘^’ (start of line) and replacing it with two spaces. This way, you can indent whole sections at once.

Lastly, consider discussing with your teacher about using a code-friendly platform like repl.it or GitHub Gists. They’re free, browser-based, and designed for code sharing. It might make both your lives easier in the long run. Good luck with your coding journey!

hey, i’ve got a quick hack for ya. use a monospace font like courier new. then, copy two spaces and paste em whenever you need to indent. it’s not perfect, but it’s way faster than manual spacing. hope this helps!

I’ve faced a similar situation before, and while Google Docs isn’t ideal for coding, there are a few workarounds. One method I found effective is using the ‘Tab’ key combined with adjusting the tab stop settings. Go to Format > Paragraph styles > Options > Indentation options. Set the ‘Tab stop’ to 0.25 inches (which is roughly equivalent to 2 spaces). Now, when you press Tab, it’ll create a 2-space indent.

Another trick is to create a custom shortcut. In Google Docs, go to Tools > Preferences > Substitutions. Add a new substitution where the ‘Replace’ field is two spaces, and the ‘With’ field is also two spaces. Choose a unique shortcut like ‘//’ or ‘;;’. This way, whenever you type your chosen shortcut, it’ll automatically insert two spaces.

These methods aren’t perfect, but they can significantly speed up your workflow in Google Docs for coding practice.