Sublime Forum

Duplicate line without selection change

#1

for example (…] is current selection)
instead of this

[this will be duplicated]

become this

this will be duplicated[this will be duplicated]

I want it to become this

[this will be duplicated]this will be duplicated

is it possible? maybe using macro or something?

0 Likes

#2

I couldn’t find a way to do this without writing a plugin, so here it is:

Create a new plugin in your user directory (something like duplicate_line_reversed.py) and copy this code in it:

[code]import sublime, sublime_plugin

class DuplicateLineReversedCommand(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.end()+1, line_contents)
else:
self.view.insert(edit, region.end(), self.view.substr(region))[/code]
Create a new keybinding (or replace the standard one) with this command (http://docs.sublimetext.info/en/latest/customization/key_bindings.html):

duplicate_line_reversed
1 Like

#3

⌘ + ⇧ + D

0 Likes