Skip to content

Instantly share code, notes, and snippets.

@lrhn
Created November 30, 2016 13:58
Show Gist options
  • Save lrhn/4daed0bd369946b29e23160c03df4f05 to your computer and use it in GitHub Desktop.
Save lrhn/4daed0bd369946b29e23160c03df4f05 to your computer and use it in GitHub Desktop.
Sublime commands to rotate the contents of selections.
import sublime
import sublime_plugin
# Rotate contents of selections forwards.
class RotateSelectionCommand(sublime_plugin.TextCommand):
def run(self, edit):
view = self.view
prevText = view.substr(view.sel()[-1])
for selection in view.sel():
text = view.substr(selection);
view.replace(edit, selection, prevText)
prevText = text;
# Rotate contents of selections backwards.
class RotateSelectionBackCommand(sublime_plugin.TextCommand):
def run(self, edit):
view = self.view
if (view.sel()):
nextText = view.substr(view.sel()[0])
for selection in reversed(view.sel()):
text = view.substr(selection);
view.replace(edit, selection, nextText)
nextText = text;
# Add to User keymap:
# {"keys": ["alt+r"], "command": "rotate_selection" },
# {"keys": ["shift+alt+r"], "command": "rotate_selection_back" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment