Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Sublime plugin
import sublime, sublime_plugin
class CalculateLinesCommand(sublime_plugin.TextCommand):
def run(self, edit):
lines={}
region = sublime.Region(0, self.view.size())
for lineRegion in self.view.lines(region):
key = self.view.substr(lineRegion)
key = key.strip(' \t\n\r')
if len(key) == 0 :
continue
i=0
if key in lines:
i=lines[key]
i=i+1
lines[key]=i
sorted_names = sorted(lines, key=lines.__getitem__, reverse=True)
index=0
self.view.erase(edit, region);
for k in sorted_names:
a="{} => {}\n".format(lines[k], k)
self.view.insert(edit, index, a)
index=index + len(a);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment