import sublime import sublime_plugin class ExpandToEndOfScopeCommand(sublime_plugin.TextCommand): def run(self, edit, begin=False): newsels = [] for s in self.view.sel(): scope = self.view.extract_scope(s.a) newsels.append(sublime.Region(scope.begin(), s.end()) if begin else sublime.Region(s.begin(), scope.end())) self.view.sel().add_all(newsels)