Last Updated: January 27, 2020
·
9.267K
· 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

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

over 1 year ago ·

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

over 1 year ago ·

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

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

over 1 year ago ·

Thank you for this terrific plugin! :)

over 1 year ago ·

@artemgordinsky You're very welcome!

over 1 year ago ·

Sweeeet stuff! Thanks!

over 1 year ago ·

BTW this is now compatie with sublime text 3!

over 1 year ago ·

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 ·

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 ·

Thanks

over 1 year ago ·