Sublime Forum

Duplicate line/selection ends up in the wrong spot

#1

The Duplicate Line command works fine if I’m on a single line and don’t have anything selected. However when I try to duplicate a selection instead of placing the selected text on a new line it places it at the end of the selection. For instance if I have the following selected:

duplicate this line
and this one as well

it will produce:

duplicate this line
and this one as wellduplicate this line
and this one as well

anyway around this? it’s extremely annoying :angry:

0 Likes

#2

If you select the newline at the end of the second line it’ll act as you ask. Doing an Expand Selection to Line before a Duplicate is one way to do this.

0 Likes

#3

ok cool. why wouldn’t you always do expand to line? it seems like that’s the expected behavior…shouldn’t that just be part of the command?

0 Likes

#4

You can chain the two commands together with a macro and bind the macro to a keybinding if you want.

0 Likes

#5

You can do that but now if I want to run the command twice it’ll grab the next line down.

Original (I’ll select and duplicate the top two lines):

it { should respond_to(:password_digest) } it { should respond_to(:email) } it { should be_valid }

After 1st run (This is correct so far):

it { should respond_to(:password_digest) } it { should respond_to(:email) } it { should respond_to(:password_digest) } it { should respond_to(:email) } it { should be_valid }

After 2nd run (This is not correct. Because we’re expanding the selection to line every time it grabbed the next line down and duplicated it too)

it { should respond_to(:password_digest) } it { should respond_to(:email) } it { should respond_to(:password_digest) } it { should respond_to(:email) } it { should be_valid } it { should respond_to(:password_digest) } it { should respond_to(:email) } it { should be_valid }

0 Likes