The command that does this is single_selection, but as far as I’m aware it doesn’t take any arguments that specifies which selection to go back to. However, it’s easy enough to add via a plugin:
class SingleSelectionLastCommand(sublime_plugin.TextCommand):
def run(self, edit):
# Save the last selection
last_sel = self.view.sel()[-1]
# Clear the selection state and then add back the saved
# selection as the new single selection.
self.view.sel().clear()
self.view.sel().add(last_sel)
# Ensure that the cursor for the last selection is visible
# in the window.
self.view.show(last_sel.b)
You can add this to the plugin from above or as it’s own plugin file (in which case, make sure to include the import statements from the other plugin to this one).
This defines a command named single_selection_last, which does what the internal single_selection command does, except that it does it for the last of the defined selections in the file instead of the first.
To put it in place, you need a key binding:
{ "keys": ["ctrl+escape"], "command": "single_selection_last", "context":
[
{ "key": "num_selections", "operator": "not_equal", "operand": 1 }
]
},
Here I used ctrl+escape as the key, so that esc does the normal action and ctrl+esc does the new one; if you only ever want to go to the last selection, you can just use escape here. The context makes sure that the binding only takes effect when there is more than one selection, since esc can potentially do a few different things based on the current editing situation.