Sublime Forum

Collapsing multiple cursors to the last location

#1

I am using Cmd-D to select and then edit a bunch of things. Now I’m done with those, and I want to carry on selecting more things further down the document. When I press Esc, the multi-cursors collapse to a single cursor in the original location. I understand why this is the default, but in my situation, I need the cursor at the last selected location so I can carry on with my editing from where I left off.

I’ve tried Shift-Esc, but that doesn’t work. Is there a shortcut or some way to make a shortcut for this?

0 Likes

#2

This is straightforward to do with a plugin:

# User/single_last_selection.py
import sublime
import sublime_plugin


class SingleLastSelectionCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        view = self.view
        sels = list(view.sel())

        if not sels:
            return

        # Always take the last selection
        last = sels[-1]

        view.sel().clear()
        view.sel().add(sublime.Region(last.a, last.b))

        view.show(view.sel()[0])

I have now demoted single_selection to Shift-Esc:

[
    {
        "keys": ["escape"],
        "command": "single_last_selection",
        "context": [
            {
                "key": "panel_has_focus",
                "operand": false,
                "operator": "equal"
            }
        ]
    },
    {
        "keys": ["shift+escape"],
        "command": "single_selection"
    }
]
2 Likes