Autoindentation in Sublime 2 text editor

30,878

Solution 1

You can use the Edit / Line / Reindent from the edit menu. Or you could try adding this to your keybindings - Default file from preferences.

{ "keys": ["f12"], "command": "reindent"}

Add a comma at the end of the code if you use the Default file instead of the users. Don't forget to select what you want indented.

You could potentially just use Visual Studio to auto-indent more obscure data that SubT can't or doesn't do well.

Good luck && select the text you want to reindent.

Solution 2

Press Ctrl+Shift+P, then I, and the option "Indentation : Reindent Lines" should come first.

Press Enter and it's done.

Solution 3

For the built in solution I like to add the option single_line: false to the key binding, as suggested by peter on this StackOverflow thread.

{ "keys": ["ctrl+k+d"], "command": "reindent" , "args": {"single_line": false}}

But this does not add new lines, as you should expect on some XML and HTML code editing.

For those you should follow Tom's answer and install the Tag plugin, or use the Indent XML plugin, available also via package control but works only on XML files.

If you choose the Tag plugin, the easiest way to use it is highlight the text to indent and then press the shortcut Ctrl+Shift+F.

If you choose the Indent XML plugin press Ctrl or Super+Shift+P and then I and the Indent XML will be the first option.

Solution 4

There is a tag plugin for formatting html/xml documents.

Share:
30,878

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin almost 2 years

    Is there an auto indentation option in Sublime 2?

    In Visual Studio I can press Ctrl+K+D to indent everything so the code is structured nicely. Is there a shortcut in Sublime 2 to do the same?

  • palaniraja
    palaniraja almost 12 years
    And you may need to reindent the line (Edit / Line / Reindent) afterwards.