Skip to content

Instantly share code, notes, and snippets.

@OdatNurd
Created January 18, 2021 04:36
Show Gist options
  • Select an option

  • Save OdatNurd/94db30476f1560e49d5d7bf2f09ff119 to your computer and use it in GitHub Desktop.

Select an option

Save OdatNurd/94db30476f1560e49d5d7bf2f09ff119 to your computer and use it in GitHub Desktop.
Plugin 101 Lesson 21 examples
import sublime
import sublime_plugin
class ReverseSelectAllCommand(sublime_plugin.TextCommand):
def run(self, edit):
span = sublime.Region(len(self.view), 0)
self.view.sel().add(span)
class RemoveSomeSelectionCommand(sublime_plugin.TextCommand):
def run(self, edit):
span = sublime.Region(7, 14) # "sublime" on line one
self.view.sel().subtract(span)
class FlipCaretCommand(sublime_plugin.TextCommand):
def run(self, edit):
new_sel = []
for sel in self.view.sel():
new_sel.append(sublime.Region(sel.b, sel.a))
self.view.sel().clear()
self.view.sel().add_all(new_sel)
class BrokenSelectCommand(sublime_plugin.WindowCommand):
def run(self):
view = self.window.active_view()
view.sel().clear()
view.sel().add(sublime.Region(14, 14))
@OdatNurd

Copy link
Copy Markdown
Author

These plugin examples are from Plugin 101 Lesson 21 on my YouTube Channel, which shows how to query and modify the selection in any file, including a demonstration of a common pitfall to fall into, why it happens and how to solve it.

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