Created
April 8, 2011 21:34
-
-
Save bobspryn/910794 to your computer and use it in GitHub Desktop.
Handles multiple lines and leaves your cursor on the newly created end line. Accepts a direction that you want to duplicate your lines of text
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, sublime_plugin | |
class DuplicateLineCommand(sublime_plugin.TextCommand): | |
def run(self, edit, direction='down'): | |
self.view.run_command("expand_selection", {"to": "line"}) | |
view = self.view | |
for region in self.view.sel(): | |
line = region | |
if line.empty(): | |
line = self.view.full_line(region) | |
line_contents = self.view.substr(line) | |
if(direction=='down'): | |
self.view.insert(edit, line.begin(), line_contents) | |
newline = sublime.Region(line.b, line.b+line.size()-1) | |
else: | |
self.view.insert(edit, line.end(), line_contents) | |
newline = sublime.Region(line.a, line.a+line.size()-1) | |
self.view.sel().clear() | |
self.view.sel().add(newline) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment