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?
I actually found it's better for my sanity to have user preferences to be defined like so:
"translate_tabs_to_spaces": true,
"tab_size": 2,
"indent_to_bracket": true,
"detect_indentation": false
The detect_indentation: false
is especially important, as it forces Sublime to honor these settings in every file, as opposed to the View -> Indentation
settings.
If you want to get fancy, you can also define a keyboard shortcut to automatically re-indent your code (YMMV) by pasting the following in Sublime -> Preferences -> Key Binding - User
:
[
{ "keys": ["ctrl+i"], "command": "reindent" }
]
and to visualize the whitespace:
"indent_guide_options": ["draw_active"],
"trim_trailing_white_space_on_save": true,
"ensure_newline_at_eof_on_save": true,
"draw_white_space": "all",
"rulers": [120],