+52
Виконано
Ctrl + Shift + D should duplicate not only current line, but current selection if available
Currently the only way to duplicate a block of code is to go through a tedious process of select->copy->go down->unindent if needed->paste.
ST1 had a plugin (poweredit) that made Ctrl+Sift+D duplicate currently selected text if it's available. If not, it would duplicate current line. This is super useful and productive feature and I think must come by default with ST2.
Thanks.
ST1 had a plugin (poweredit) that made Ctrl+Sift+D duplicate currently selected text if it's available. If not, it would duplicate current line. This is super useful and productive feature and I think must come by default with ST2.
Thanks.
Відповідь
+5
I've hacked the existing duplicate_line.py a bit. It copies the current line if nothing selected. Otherwise it inserts the selection after the selection. For duplicating complete lines you have to select the whole line (including the newline character).
import sublime_plugin
class DuplicateLineCommand(sublime_plugin.TextCommand):
def run(self, edit):
for region in self.view.sel():
line = region
if line.empty():
line = self.view.full_line(region)
line_contents = self.view.substr(line)
self.view.insert(edit, line.end(), line_contents)
import sublime_plugin
class DuplicateLineCommand(sublime_plugin.TextCommand):
def run(self, edit):
for region in self.view.sel():
line = region
if line.empty():
line = self.view.full_line(region)
line_contents = self.view.substr(line)
self.view.insert(edit, line.end(), line_contents)
+2
I've seen that some of my co-workers did indent it wrongly. You have to indent the last two lines at the same column like the "if line.empty()" is, otherwise nearly nothing will happen.
As always you install it by putting it into your User folder.
As always you install it by putting it into your User folder.
+1
Very nice, thank you.
here is a screenshot for the indentation for those who don't know python too well:
http://twitpic.com/3y9lt7
The script shall be put for a default Mac OS X installation under ~/Library/Application Support/Sublime Text 2/Packages/User/duplicate_line.py
here is a screenshot for the indentation for those who don't know python too well:
http://twitpic.com/3y9lt7
The script shall be put for a default Mac OS X installation under ~/Library/Application Support/Sublime Text 2/Packages/User/duplicate_line.py
+1
+1, and there is some inconsistency while 'Delete Line' operates on selection but 'Duplicate Line' doesn't.
Служба підтримки клієнтів працює на UserEcho
This was done in build 2091