After I select some text by pressing Ctrl+D , Ctrl+D , Ctrl+D , Ctrl+D , Ctrl+D , Ctrl+D
I want to return to my original position not the first instance on the page.
Is this possible to do?
After Ctrl+D press ESC and return back to start
I’m not entirely sure I understand what you mean by “original position not the first instance on the page”, but it if helps, pressing Esc
when you have more than one selection will remove the selection and jump back to where the first cursor is.
This is the same behavior that Atom had, it’s very intuitive behavior
Say your document looks like the following:
dog
cat <---- 2. cursor ends up here
cat <---- 1. highlight cat here, press Ctrl+D, Ctrl+D, Ctrl+D, Ctrl+D, ESC
dog
cat
The use case is like this. I’m looking at a line of code, perhaps I want to see how this a function is called elsewhere in the code. I use Ctrl+D see the next similar code… Again I press Ctrl+D see another use of the function… I do that a few times, now I have seen every instance of this function. Okay I’m done, ready to return to where I started and correctly implement my change. So I want to return to the place where I started… But in Sublime you end up on the first line of the file that matches, – not back to where you started. So I’m forced to try to determine where I was.
Instead of the current behavior I want to hit ESC and get back to what I was doing.
Definitely possible to do by writing a Python plugin. I have one that does something a bit different (lets you choose which selection will remain when next pressing Esc).
Basically there needs to be a replacement for the command bound to Esc by default (single_selection
), which instead takes some previously set aside data into account.
class SingleSelectionUserChosen(sublime_plugin.TextCommand):
def run(self, edit: sublime.Edit) -> None:
if reg_str := self.view.settings().get(CycleShownSelection.__name__):
reg = eval(reg_str, {"Region": sublime.Region})
self.view.sel().clear()
self.view.sel().add(reg)
else:
self.view.run_command("single_selection")