Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support vi's ''/`` (jump to position before last jump) #137

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
25 changes: 23 additions & 2 deletions vintage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1016,13 +1016,26 @@ def run(self, edit):
transform_selection_regions(self.view, shrink_to_first_char)

class ViSetBookmark(sublime_plugin.TextCommand):
@classmethod
def _run(kls, view, character, regions=None):
"""
This exposes bookmark-setting on a native-level, so that
commands can pass a view.sel() directly without having to
convert it into a list/dict/etc. deeply.
"""
if regions is None:
regions = list(view.sel())
view.add_regions("bookmark_" + character, regions,
"", "", sublime.PERSISTENT | sublime.HIDDEN)

def run(self, edit, character):
sublime.status_message("Set bookmark " + character)
self.view.add_regions("bookmark_" + character, [s for s in self.view.sel()],
"", "", sublime.PERSISTENT | sublime.HIDDEN)
self._run(self.view, character)

class ViSelectBookmark(sublime_plugin.TextCommand):
def run(self, edit, character, select_bol=False):
frozen_regions = list(self.view.sel())

self.view.run_command('select_all_bookmarks', {'name': "bookmark_" + character})
if select_bol:
sels = list(self.view.sel())
Expand All @@ -1031,6 +1044,9 @@ def run(self, edit, character, select_bol=False):
start = self.view.line(r.a).begin()
self.view.sel().add(sublime.Region(start, start))

ViSetBookmark._run(self.view, "`", frozen_regions)
ViSetBookmark._run(self.view, "'", frozen_regions)

g_macro_target = None

class ViBeginRecordMacro(sublime_plugin.TextCommand):
Expand Down Expand Up @@ -1117,3 +1133,8 @@ def run(self, direction):
self.window.focus_group(matches.next())
except StopIteration:
return

class ViRecordLastEdit(sublime_plugin.EventListener):
def on_modified(self, view):
""" Record the cursor's position at the last edit in the view. """
ViSetBookmark._run(view, ".")