64

Possible Duplicate:
Indenting code in Sublime text 2?

I'm trying to learn keyboard shortcuts in Sublime. What is the keyboard shortcut in Sublime Text 2 for reindent? According to some pages it should be TAB but that only indents, not reindents.

Community
  • 1
  • 1
Yaron Naveh
  • 23,560
  • 32
  • 103
  • 158

2 Answers2

218

You can find it in Edit>>Line>>Reindent, but it does not have a shortcut by default. You can add a shortcut by going to the menu Preferences - Keybindings-User, then add there (the config file takes as a JSON format):

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

(example of using the F12 key for that functionality)

Volker E.
  • 5,911
  • 11
  • 47
  • 64
Kummo
  • 3,602
  • 5
  • 24
  • 29
  • 51
    You can also add `"args": {"single_line": false}` to reindent the whole text – Ayonix Nov 01 '13 at 15:05
  • 5
    `[ { "keys": ["super+shift+l"], "command": "reindent"} ]` like atom – Nick Oct 10 '14 at 16:54
  • @Ayonix please provide full syntax. And also if I want to add two bindings for whole text and for selected text, how I will do. Please share full syntax. Thanks in advance. – Sanjay Goswami Jul 14 '16 at 08:11
  • 8
    @PlanetHackers `[ { "keys": ["f12"], "command": "reindent", "args": {"single_line": false}}, { "keys": ["f11"], "command": "reindent"} ]` should do – Ayonix Aug 23 '16 at 12:43
  • Xcode style: `{ "keys": ["ctrl+i"], "command": "reindent"}` ;-) – d4Rk Aug 30 '18 at 09:47
  • For Mac, I use this: `{"keys": ["super+\\"], "command": "reindent", "args": {"single_line": false}}` – blackandorangecat Mar 24 '19 at 14:29
6

I use cmd-[ and cmd-] for indenting but I am not sure exactly what you mean by "reindent"...

Ahh, OK I get your question now, you can use the command to re-calculate and apply correct indentation to a file. For example, if you open a file that has had been programmatically altered and had whitespace stripped or tabs removed you would use the reindent command to restore correct formatting.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
DyeA
  • 324
  • 2
  • 8