Skip to content

Instantly share code, notes, and snippets.

@simonhaenisch
Last active March 9, 2018 18:42
Show Gist options
  • Save simonhaenisch/a330b6e5b7965a3c9eb18639924b95a0 to your computer and use it in GitHub Desktop.
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
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
[
{
"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