Skip to content

Instantly share code, notes, and snippets.

@agibsonsw
Created March 4, 2012 19:21
Show Gist options
  • Save agibsonsw/1974433 to your computer and use it in GitHub Desktop.
Save agibsonsw/1974433 to your computer and use it in GitHub Desktop.
ST Python to move between last edits
import sublime, sublime_plugin
POSITIONS = {}
class LastEditLineCommand(sublime_plugin.TextCommand):
posn = 0
def run(self, edit):
vid = self.view.id()
if not POSITIONS.has_key(vid): return
if len(POSITIONS[vid]) <= self.posn + 1:
self.posn = 0
self.view.sel().clear()
self.view.show(POSITIONS[vid][-(self.posn+1)])
self.view.sel().add(self.view.line(POSITIONS[vid][-(self.posn + 1)]))
self.posn = (self.posn + 1) % 5
class CaptureEditing(sublime_plugin.EventListener):
def on_modified(self, view):
sel = view.sel()[0]
vid = view.id()
curr_line, _ = view.rowcol(sel.begin())
if not POSITIONS.has_key(vid):
POSITIONS[vid] = [curr_line, sel.begin()]
elif POSITIONS[vid][0] != curr_line:
POSITIONS[vid].append(sel.begin())
POSITIONS[vid][0] = curr_line
if len(POSITIONS[vid]) > 6: POSITIONS[vid].pop(1)
@agibsonsw
Copy link
Author

Add a shortcut key to run last_edit_line and you can press it to repeatedly cycle to the last five edit positions of the current document/view.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment