What is the option in the Key Bindings file that I would use to set up a keyboard shortcut for the menu item
View -> Indentation -> Convert Indentation To Spaces
I've tried the following, but can't figure out how to trigger the option I see in the above mentioned menu
{ "keys": ["super+t"], "command": "convert_to_tabs" },
{ "keys": ["shift+super+t"], "command": "convert_to_spaces" },
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.
Use Cmd (Mac) or Alt (Windows) with the number keys 0–9 to switch between tabs in Sublime Text. For example hit Cmd–2 (Mac) or Alt–2 (Windows) to switch to the second tab. You can also use Ctrl–Tab (Mac and Windows) to cycle through your tabs.
In Sublime Text, while editing a Python file: Sublime Text menu -> Preferences -> Settings: Syntax-Specific: { "tab_size": 4, "translate_tabs_to_spaces": true } Or, In the bottom right of the editor, click the part of the status bar where it says "Tab size" click "Convert Indentation to Spaces" to correct an existing ...
Convert spaces to tabs (from Eric Muyser):
{ "keys": ["ctrl+shift+x"], "command": "unexpand_tabs", "args": { "set_translate_tabs": false } }
Convert tabs to spaces (from mVChr):
{ "keys": ["ctrl+shift+y"], "command": "expand_tabs", "args": { "set_translate_tabs": true } }
Original Answer Below
You could do it with one command each (expand_tabs
and unexpand_tabs
), but it would also be a good idea to toggle "Indent Using Spaces". Here is a macro that I saw somewhere (I forget where.)
Tabs -> Spaces
Save as "convert_tabs_to_spaces.sublime-macro" inside of your "Packages/User" folder
[
{
"args":
{
"set_translate_tabs": true
},
"command": "expand_tabs"
}
]
Add this to your keybindings file:
{ "keys": ["ctrl+shift+x"], "command": "run_macro_file", "args": {"file": "Packages/User/convert_tabs_to_spaces.sublime-macro"} },
Spaces -> Tabs
Similar file name and keybinding
[
{
"args":
{
"set_translate_tabs": false
},
"command": "unexpand_tabs"
}
]
I used this until I saw that you could left click the indentation setting in the Status Bar and change it from there.
adapted from here
"convert_tabs_to_spaces.py"
import sublime, sublime_plugin
class ConvertTabsToSpaces(sublime_plugin.TextCommand):
def run(self, edit):
self.view.run_command('expand_tabs', {"set_translate_tabs": True})
.
keybinding: { "keys": ["ctrl+shift+x"], "command": "convert_tabs_to_spaces"},
"convert_spaces_to_tabs.py"
import sublime, sublime_plugin
class ConvertSpacesToTabs(sublime_plugin.TextCommand):
def run(self, edit):
self.view.run_command('unexpand_tabs', {"set_translate_tabs": False})
.
keybinding: { "keys": ["ctrl+shift+y"], "command": "convert_spaces_to_tabs"},
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