Duplicate Line

Mar 13

Duplicate Line

Here’s something that I have in EditPlus, but I haven’t found in other editors: a “duplicate line” shortcut.

In EditPlus, you can have your cursor in a line, hit CTRL-J, and the line will be copied immediately underneath the current line. Hit CTRL-J four or five times and you get four or five identical lines.

This is really handy — more than you’d think. For instance, tonight when adding “Import” statements at the top of a .Net Web form in Visual Studio, I had to manually copy the last line, then paste it in. Tedious.

There are lots of instances in programming where you have multiple, consecutive lines that differ very slightly, so a quick way to copy and paste really saves time. Think of table rows in HTML, for example.

So why isn’t “Duplicate Line” found in more editors? When I work in any editor besides EditPlus, this is the command I miss right away and get frustrated when I can’t find a replacement for it.


Comments

by Alex,   March 14, 2006 4:42 AM  

I've always loved Vi for its handling of invaluable shortcuts like this. Duplicate line in Vi: 'yyp'.


by bob,   March 14, 2006 6:15 AM  

ctrl+d in notepad++

http://notepad-plus.sourceforge.net/


by iii,   March 14, 2006 7:32 AM  

i'm a vi fan also.

that being said - i'm leary of features that facilitate copying and pasting. i realize that for html development it's useful, but i've slogged my way through enough unfactored code to think that maybe pasting is something we should prohibit editors from doing all together.

fortunately, vi also has good global search and replace facilities.


by Paul,   March 14, 2006 8:54 AM  

Zend does this for PHP, ctrl+d.


by Joe,   March 14, 2006 10:01 AM  

Alex beat me to the 'yyp'. In vi, you can also say something like 'yy 3p' (copy line and paste it 3 times) or '4y 3p' (copy the next 4 lines, then paste them 3 times)


by M.,   March 15, 2006 11:17 AM  

I'm pretty sure you can do it in VS.NET with Resharper, though I don't remember the actual shortcut key (as the duplicate line isn't a feature I personally use). If you're not using Resharper... you're missing out! - it can do a helluva lot more than just duplicate lines ;-)


by Deane,   March 15, 2006 11:23 AM  

I’m pretty sure you can do it in VS.NET with Resharper

So I need a $149 plugin to get a duplicate line shortcut?


by xmanoel,   March 19, 2006 4:14 AM  

I guess most of the editors have similar stuff... Don't they?

I do remember my very old MSDOS days with TDE.

And for anybody using Windows nowadays, Duplicate line is: Ctrl-C Ctrl-V

Yup!!


by Mike,   July 3, 2006 7:43 PM  

Ok, here's a free one for you from another EditPlus user, this works in VisualStudio 2005 (8.0) and probably 7.1 and 7.0:

Sub DuplicateLine()
    Dim line As String
    DTE.ActiveDocument.Selection.StartOfLine(0)
    DTE.ActiveDocument.Selection.EndOfLine(True)
    line = DTE.ActiveDocument.Selection.Text
    DTE.ActiveDocument.Selection.EndOfLine()
    DTE.ActiveDocument.Selection.NewLine()
    DTE.ActiveDocument.Selection.StartOfLine(0)
    DTE.ActiveDocument.Selection.Text = line
End Sub

If you assign the macro to CTRL-j it works just like EditPlus except a little bit slower, but then again, everything is slower in VS2005.

All you have to do is paste it in one of the existing modules in the Macro IDE. To assign to a key, searxh for "Duplicate" in the keyboard customizing dialog.

-Mike


by Noam,   September 17, 2008 3:19 AM  

Thank Mike!!! you rule;

if you want to prefect your macro, you need to add the event were some text is already selected, and copy this selected text only!

I used to work in Zend (PHP) and this feature was one of my favourites

Noam


by Gabriel,   August 27, 2010 12:58 PM  

Wow Mike Thank you so much, I just found your macro today and it worked perfectly. I am also used to Control+D from Notepad++ and it is a petty that duplicate line doesnt exist in VS, but now its all good! ;)

Many thanks!


by qnx,   September 9, 2010 6:35 AM  

Eclipse have that since always... VS is years behind...


by Kevlyn,   October 19, 2011 6:25 AM  

Wow, great thing I have learned today. but my query is, how to find duplicate lines in Editplus? Can You help me?



Add Comment