Created
May 25, 2012 16:10
-
-
Save dtao/2788978 to your computer and use it in GitHub Desktop.
Sublime Text plugin to increment/decrement all selected numbers
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 | |
import sublime_plugin | |
class NumberCommand(sublime_plugin.TextCommand): | |
def run(self, edit): | |
selection = self.view.sel() | |
for region in selection: | |
try: | |
value = int(self.view.substr(region)) | |
self.view.replace(edit, region, str(self.op(value))) | |
except ValueError: | |
pass | |
def is_enabled(self): | |
return len(self.view.sel()) > 0 | |
class IncrementCommand(NumberCommand): | |
def op(self, value): | |
return value + 1 | |
class DecrementCommand(NumberCommand): | |
def op(self, value): | |
return value - 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey buddy, thanks for this code, i am a beginner kindly please tell me how i can use this code...