Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autoindent on Sublime Text

Are there any command/shortcut to auto-indent all my code on the page at once on Sublime Text 3?

e.g: On NetBeans I can do this with Alt+Shift+F.

like image 814
Thiago Anderson Avatar asked Jun 28 '17 13:06

Thiago Anderson


People also ask

How do I change tabs to 4 spaces in sublime?

To configure the tab width in Sublime Text 3, click on “View” in the top bar, then click on “Indentation” in the drop-down list. Next, in the second level of the drop-down list select the width you want a tab to take up. Sublime Text 3 defaults to tabs being four spaces wide.

How do I prettify code in Sublime Text?

sublime-settings : Ctrl+Shift+P or Cmd+Shift+P in Linux/Windows/OS X. type htmlprettify , select Set Plugin Options.

How do I fix sublime indentations?

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.

How do I align HTML code in Sublime Text 3?

One option is to type [command] + [shift] + [p] (or the equivalent) and then type 'indentation'. The top result should be 'Indendtation: Reindent Lines'. Press [enter] and it will format the document.


2 Answers

That's quite simple in Sublime. Just Ctrl+Shift+P (or Command+Shift+P on MacOS) to open the tools pallet, type reindent, and pick Indentation: Reindent Lines. It should reindent all the file you are in, just remember to save before running the command, or it may not appear.

like image 85
Luan Gonçalves Barbosa Avatar answered Oct 22 '22 15:10

Luan Gonçalves Barbosa


Auto-indenting on Sublime Text 3 - "Key Bindings"

Just add this binding to your "Key Bindings - User" file:

Preferences > Key Bindings - users

{"keys": ["alt+shift+f"], "command": "reindent", "args": {"single_line": false}} 

And adding this code between the square brackets.

Now you can use Alt + Shift + f as your auto-indent shortcut

You can also use the "reindent" feature through the command palette. Ctrl + Shift + P


Ressources:

Auto-indenting on Sublime Text 3 by Osvaldo Zonetti

Create a Keybinding by Joe Lloyd

like image 40
chebaby Avatar answered Oct 22 '22 14:10

chebaby