Created
November 30, 2016 13:58
-
-
Save lrhn/4daed0bd369946b29e23160c03df4f05 to your computer and use it in GitHub Desktop.
Sublime commands to rotate the contents of selections.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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