Tabs and Spaces - Smarter Indentation

Brian Pool

When you're programming, indentation is something you shouldn't have to think about, as an IDE should handle most of the details nowadays. With Replit, you don't have to think about what happens when you press tab. We're releasing a suite of new indentation and whitespace related features that will make the code editing experience even better.

Automatic indentation detection

Replit can now automatically detect the indentation of files that you open. That means if a file was indented with two spaces, you'll automatically get two spaces when you press tab regardless of what your normal settings are.

Also, adding indentation detection required that we unrestrict what indentation sizes you're allowed to use. Now, you can use any size between 1 and 16. That means if you use an uncommon indentation unit like 3 spaces, you're covered now!

The indentation Swiss Army knife

There is now an element in the status bar of the code editor that shows your current indentation settings for the file. You can click on this element to show a menu which lets you do a number of things:

  • Change the indentation unit for the file
  • View what Replit thinks the indentation for the file is (indentation detection)
  • Convert between different indentation units, e.g. from 2 spaces to 4 spaces
  • Re-indent the file so that everything uses the same indent characters

Smarter pasting

Replit is now a lot smarter about pasting, with the indentation of whatever you copied and the indentation of where you pasted taken into account.

This feature doesn't use a language formatter/linter, so it works no matter what language you're using. Under the hood, we're analyzing whatever you copied and re-indenting it to match the indentation of wherever you pasted. This re-indentation preserves the differences in indentation between copied lines, so the code you copied and what was pasted should look identical, regardless of where you pasted.

Showing whitespace

We've added a setting so that you can show whitespace in the editor. You can customize what kinds of whitespace are shown, so if e.g. you only care to show trailing whitespace, you can do that.

The future

We are still working on adding new features and improvements to the Replit workspace. There will be more to show later, so stay tuned!

Want to be a part of our journey to make the best code editing experience? Come work with us!

More blog posts