How to fix/convert space indentation in Sublime Text?

Magne picture Magne · Feb 8, 2013 · Viewed 154k times · Source

Example: If I have a document with 2 space indentation, and I want it to have 4 space indentation, how do I automatically convert it by using the Sublime Text editor?

Answer

Magne picture Magne · Feb 8, 2013

Here's a neat trick in Sublime Text 2 or 3 to convert your indentation spacing in a document.

TL;DR:

Converting from 2 spaces to 4 spaces:

Ensure tab width is set to 2. Convert your 2-space indentation to tabs, switch to tab width 4, and then convert the indentation back to spaces.

The detailed description:

Go to:

View -> Indentation

It should read:

  • Indent using spaces [x]
  • Tab width: 2

Select:

  • Convert Indentation to Tabs

Then Select:

  • Tab width: 4
  • Convert Indentation to Spaces

Done.