While playing with this, I found that if you select completely unindent first, then reindent will work as expected. This seems to be a bug in the reindent , which occurs when the indent is not a multiple of the size of the "tab" that is set.
Therefore, we can work around this error by changing your shortcut to completely deselect and then delay it again.
From the Tools menu, select Developer β New Plugin...
Select all and replace it with the following:
import sublime import sublime_plugin import re class UnindentAndReindentCommand(sublime_plugin.TextCommand): def run(self, edit): while any([sel for sel in self.view.sel() if re.search('^[ \t]+', self.view.substr(sel.cover(self.view.line(sel.begin()))), re.MULTILINE)]): self.view.run_command('unindent') self.view.run_command('reindent', { 'single_line': False })
Save it in the place that ST offers, something like fix_reindent.py - the file extension is important, but there is no base name.
Then change the key binding to use the new unindent_and_reindent command we just created:
{ "keys": ["ctrl+shift+f"], "command": "unindent_and_reindent" }
And now it will correctly rewrite your code.
source share