Sublime Text 2 allows you to convert tabs to spaces in existing files manually (View -> Indentation -> Convert indentation to spaces). However, this can be done automatically when saving the file.
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.
Changing default indentation settings The following File Type Preferences determine the indentation settings: translateTabsToSpaces: set to either 'true' or 'false'. If true, then when tab is pressed, an equivalent number of spaces will be inserted into the buffer instead. Defaults to false.
by pressing ctrl+f12, it will reindent your file to a tab size of 4. if you want a different tab size, you just change the "value" number.
On the bottom right-hand corner of your Sublime Text window, you'll see an indentation indicator that looks a lot like this:
Clicking it will open a menu with options to adjust your indentation preferences, and more importantly, Convert Indentation to Tabs/Spaces
.
The same menu is listed under View -> Indentation
.
At the bottom of the Sublime window, you'll see something representing your tab/space setting.
You'll then get a dropdown with a bunch of options. The options you care about are:
Apply your desired setting to the entire document.
Hope this helps.
As you might already know, you can customize your indention settings in Preferences.sublime-settings
, for example:
"detect_indentation": true,
"tab_size": 4,
"translate_tabs_to_spaces": false
This will set your editor to use tabs that are 4 spaces wide and will override the default behavior that causes Sublime to match the indention of whatever file you're editing. With these settings, re-indenting the file will cause any spaces to be replaced with tabs.
As far as automatically re-indenting when opening a file, that's not quite as easy (but probably isn't a great idea since whitespace changes wreak havoc on file diffs). What might be a better course of action: you can map a shortcut for re-indention and just trigger that when you open a new file that needs fixing.
You can use the command palette to solve this issue.
Step 1: Ctrl + Shift + P
(to activate the command palette)
Step 2: Type "Indentation", Choose "Indentation: Convert to Tabs"
In my case, this line solved the problem:
"translate_tabs_to_spaces": false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With