Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h2>Simple Version</h2> <p>Convert spaces to tabs (from Eric Muyser):</p> <pre><code>{ "keys": ["ctrl+shift+x"], "command": "unexpand_tabs", "args": { "set_translate_tabs": false } } </code></pre> <p>Convert tabs to spaces (from mVChr):</p> <pre><code>{ "keys": ["ctrl+shift+y"], "command": "expand_tabs", "args": { "set_translate_tabs": true } } </code></pre> <p>Original Answer Below</p> <hr> <p>You could do it with <a href="http://www.sublimetext.com/docs/2/indentation.html" rel="noreferrer">one command each</a> (<code>expand_tabs</code> and <code>unexpand_tabs</code>), but it would also be a good idea to toggle "Indent Using Spaces". Here is a macro that I saw somewhere (I forget where.)</p> <h2>Macro Version</h2> <p><strong>Tabs -> Spaces</strong></p> <p>Save as "convert_tabs_to_spaces.sublime-macro" inside of your "Packages/User" folder</p> <pre><code>[ { "args": { "set_translate_tabs": true }, "command": "expand_tabs" } ] </code></pre> <p>Add this to your keybindings file:</p> <pre><code> { "keys": ["ctrl+shift+x"], "command": "run_macro_file", "args": {"file": "Packages/User/convert_tabs_to_spaces.sublime-macro"} }, </code></pre> <p><strong>Spaces -> Tabs</strong></p> <p>Similar file name and keybinding</p> <pre><code>[ { "args": { "set_translate_tabs": false }, "command": "unexpand_tabs" } ] </code></pre> <p>I used this until I saw that you could left click the indentation setting in the Status Bar and change it from there.</p> <h2>Edit:</h2> <h2>Plugin Version</h2> <p><a href="http://www.butlerpc.net/blog/2012/07/sublime-text-2-plugin-to-convert-tabs-to-spaces-on-save/" rel="noreferrer">adapted from here</a></p> <p><strong>"convert_tabs_to_spaces.py"</strong></p> <pre><code>import sublime, sublime_plugin class ConvertTabsToSpaces(sublime_plugin.TextCommand): def run(self, edit): self.view.run_command('expand_tabs', {"set_translate_tabs": True}) </code></pre> <p>.</p> <p>keybinding: <code>{ "keys": ["ctrl+shift+x"], "command": "convert_tabs_to_spaces"},</code></p> <p><strong>"convert_spaces_to_tabs.py"</strong></p> <pre><code>import sublime, sublime_plugin class ConvertSpacesToTabs(sublime_plugin.TextCommand): def run(self, edit): self.view.run_command('unexpand_tabs', {"set_translate_tabs": False}) </code></pre> <p>.</p> <p>keybinding: <code>{ "keys": ["ctrl+shift+y"], "command": "convert_spaces_to_tabs"},</code></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload