hiybmw
Last Updated: February 25, 2016
·
8.767K
· wjonthomas

Better "duplicate line" command for Sublime Text 2

I wrote a better duplicate line command for Sublime Text 2 to behave the way it should. Ok, maybe it's just preference, but I think you'll find it very useful.

It behaves more like Eclipse. You can have your cursor anywhere in a line and duplicate the full line. This also works with multiple lines. Again, the nice thing here is that it doesnt' care where your curor is. You can lazily highlight a group of lines, use the shortcut, and you'll get an idential duplicate of the lines.

Here's a quick example. I've selected some lines below, but I was lazy about it. Meaning I didn't select the hard beginning of the first line, or the hard end of the last line.

Picture

When I run my command, I get a perfect duplicate:

Picture

And it keeps the selection like you would expect, so you can duplicate to your heart's content.

Upvote if this is helpful for you and then go check out the readme on github. I encourage you to try it out. You won't go back.

https://github.com/wjthomas9/duplicate-lines

Check out some of my other tips and follow me here: @wjonthomas

10 Responses
Add your response

4584

I submitted a pull request to add this to the Submlime package manager. Hopefully it's added soon!

over 1 year ago ·
4721

this kills it bro! I love it. A definite new favorite part of my workflow with Sublime! Thanks :P

over 1 year ago ·
5058

Now available as a Sublime Text 2 plugin. Go get it!

Install instructions at
https://github.com/wjthomas9/duplicate-lines

over 1 year ago ·
8106

Thank you for this terrific plugin! :)

over 1 year ago ·
8110

@artemgordinsky You're very welcome!

over 1 year ago ·
8555

Sweeeet stuff! Thanks!

over 1 year ago ·
12441

BTW this is now compatie with sublime text 3!

over 1 year ago ·
13460

It seems to me the command does not work properly. As a result of the command, a new block of code begins on the same line where the old ends. But it must begin on a new line. (Sublime 3 - HTML / CSS )

over 1 year ago ·
13461

I noticed that as well when I switched to Sublime Text 3. It didn't do that in Sublime Text 2. However, I have noticed that if there is a blank line after what you're trying to duplicate, it works. I've also noticed some other syntaxes where it behaved starngely. I'm not an experienced Python developer, but I hope to take a look and see if I can fix this. Thanks for reporting! (If anyone knows how to fix this, please feel free to fork it!)

over 1 year ago ·
18425

Thanks

over 1 year ago ·