Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Indenting code in Sublime text 2?

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

like image 842
Kimpo Avatar asked Feb 29 '12 07:02

Kimpo


People also ask

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 indent multiple lines in Sublime Text 3?

shift+tab is really useful when you select multiple lines. lets say i have 10 lines of code, and i want to indent all of them, you don't have to use multi-cursor, you can just select the lines, and press tab, or shift-tab to unindent.

How do you indent a group of codes?

use Ctrl + ] to indent them.


1 Answers

You can find it in EditLineReindent, but it does not have a shortcut by default. You can add a shortcut by going to the menu PreferencesKeybindingsUser, then add there:

{ "keys": ["f12"], "command": "reindent", "args": {"single_line": false} }   

(example of using the F12 key for that functionality)

The config files use JSON-syntax, so these curly braces have to be placed comma-separated in the square-brackets that are there by default. If you don't have any other key-bindings already, then your whole KeybindingsUser file would look like this, of course:

[     { "keys": ["f12"], "command": "reindent", "args": {"single_line": false}} ] 
like image 106
Bernd Elkemann Avatar answered Nov 21 '22 14:11

Bernd Elkemann