Skip to content

Instantly share code, notes, and snippets.

@gornostal
Created July 1, 2012 12:34
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save gornostal/3028289 to your computer and use it in GitHub Desktop.
Sublime plugin for duplicating lines
import sublime, sublime_plugin
class DuplicateLineCommand(sublime_plugin.TextCommand):
def run(self, edit):
for region in self.view.sel():
if region.empty():
line = self.view.line(region)
line_contents = self.view.substr(line) + '\n'
self.view.insert(edit, line.begin(), line_contents)
else:
start = self.view.line(region.begin()).begin()
end = self.view.line(region.end()).end()
region = sublime.Region(start, end)
content = self.view.substr(region) + '\n'
self.view.insert(edit, region.begin(), content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment