Created
July 22, 2012 23:14
-
-
Save Kalli/3161353 to your computer and use it in GitHub Desktop.
Insert Line Numbers Sublime Text 2 Plugin
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
'''Sublime Text 2 plugin for inserting the line numbers of a text document or a selection within it ''' | |
import sublime | |
import sublime_plugin | |
class InsertLineNumbersCommand(sublime_plugin.TextCommand): | |
def run(self, edit): | |
selected_region = self.view.sel()[0] | |
if selected_region.size() == 0: | |
text = self.view.substr(sublime.Region(0, self.view.size())) | |
else: | |
text = self.view.substr(sublime.Region(selected_region.begin(), selected_region.end())) | |
lines = text.split("\n") | |
text = "" | |
for idx, val in enumerate(lines): | |
text = text + str(idx + 1) + ". " + val + "\n" | |
if selected_region.size() == 0: | |
self.view.replace(edit, sublime.Region(0, self.view.size()), text) | |
else: | |
self.view.replace(edit, sublime.Region(selected_region.begin(), selected_region.end()), text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment