Last active
March 9, 2018 18:42
-
-
Save simonhaenisch/a330b6e5b7965a3c9eb18639924b95a0 to your computer and use it in GitHub Desktop.
Sublime Text 3 plugin for in-/decrementing a multi-selection or creating an ordered (incrementing) list (starting with the value of first selection) #sublimetext
This file contains 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, sublime_plugin | |
class IncrementSelectionCommand(sublime_plugin.TextCommand): | |
# increments each selected number by one | |
def run(self, edit): | |
for region in self.view.sel(): | |
value = int(self.view.substr(region)) | |
self.view.replace(edit, region, str(value + 1)) | |
class DecrementSelectionCommand(sublime_plugin.TextCommand): | |
# decrements each selected number by one | |
def run(self, edit): | |
for region in self.view.sel(): | |
value = int(self.view.substr(region)) | |
self.view.replace(edit, region, str(value - 1)) | |
class IncrementSelectionAsListCommand(sublime_plugin.TextCommand): | |
# creates an ordered (incrementing) list starting with the value of first selection | |
def run(self, edit): | |
count = int(self.view.substr(self.view.sel()[0])) # get initial count from first selection | |
for region in self.view.sel(): | |
self.view.replace(edit, region, str(count)) | |
count += 1 |
This file contains 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
[ | |
{ | |
"keys": ["alt+up"], | |
"command": "increment_selection" | |
}, | |
{ | |
"keys": ["shift+alt+up"], | |
"command": "increment_selection_as_list" | |
}, | |
{ | |
"keys": ["alt+down"], | |
"command": "decrement_selection" | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment