503

Is there a shortcut for Duplicate Line command in Visual Studio 2008?

Some similar examples:

Guilherme Fidelis
  • 1,022
  • 11
  • 20
Posto
  • 7,362
  • 7
  • 44
  • 61
  • 7
    Just for info, one of the many benefits offered by ReSharper is the ability to do this. – AakashM Feb 17 '10 at 08:08
  • 2
    https://visualstudiogallery.msdn.microsoft.com/830a6482-3b8f-41a8-97b5-b9c581e5ad8b Download this and alt + D will duplicate your selection or if nothing is highlighted it will duplicate the entire line. Unfortunately visual basic macros don't seem to work in 2013, only js macros. – ss7 May 17 '15 at 05:29
  • 1
    OMG, what is the problem to assign combination a person like for duplicating line??? I used to Eclipse. And Ctrl + D is for removing line. Why it's so complicated in VS??? – Andrii Muzychuk Aug 02 '15 at 12:46
  • 2
    @mghhgm below is the answer you're looking for.(shift+alt+down or shift+alt+up) – Victor Barrantes Dec 01 '16 at 05:55
  • 1
    The vim example is not duplicating, it's ctrl+c;ctrl+v. "Yank" cuts, and p pastes. It's not quite the same as the other examples. – ANeves May 04 '17 at 17:56
  • This has now become a default command in Visual Studio 2017, bound to Ctrl-E, V, but you can bind it to anything. Can duplicate line (if nothing selected) or duplicate selection, see: https://dailydotnettips.com/did-you-know-now-you-can-duplicate-line-of-code-without-loosing-your-clipboard-content-within-visual-studio/ – Abel May 27 '18 at 00:09

32 Answers32

536

In Visual Studio 2022

Ctrl + E, V

In Visual Studio 2019

Ctrl + D

In Visual Studio 2017 (v15.6 and after)

Ctrl + D

In Visual Studio 2017 (pre v15.6)

(edit) This feature is now built-in in VS2017: Ctrl + E, V duplicates a line if nothing is selected, or duplicates selection. You can assign it to a different key combination, or find it in the menu:

Duplicate line in VS2017

See this reference for more information.

Pre VS2017, built-in method using clipboard

As @cand mentioned, you can just do Ctrl + C ; Ctrl + V.

Ctrl + C will copy the line if nothing is selected.

Macro solution (pre VS2017)

If you'd like to implement a more complete solution, perhaps to create a simpler keyboard shortcut or you don't want to effect the clipboard, see this guide:

Visual Basic:

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports System.Diagnostics
 
Public Module DuplicateLastLineModule
    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
End Module

To create the macro, just go to the macro explorer ("Tools->Macros->Macro Explorer" or Alt+F8) and copy paste the code in a new module. Now just assign a keyboard shortcut to it:

  1. go to Tools->Options...
  2. under Environment, click Keyboard
  3. in the "Show Commands Containing" textbox, enter "duplicate" (this according to the name you gave the module.)
  4. you should now see the macro in the list below
  5. choose "Text Editor" from the "Use new shortcut in" list
  6. set focus in the "Press shortcut keys" textbox and hit the combination on the keyboard you wish to use for it (Ctrl+Shift+D in my case)
  7. hit the "Assign" button
  8. you should now see the shortcut in the "Shortcuts for selected command" textbox
  9. hit the OK button

And that's it. Enjoy!

Michele Bortot
  • 195
  • 2
  • 9
Wael Dalloul
  • 22,172
  • 11
  • 48
  • 57
  • 3
    I just tried it, and it's interesting that it repeats some extra characters when there is a "server-side code block" with short tags, like this: `
    Profile.UserName: <%=Profile.UserName %>
    ` - after duplicating this line using this macro, it becomes the following: `
    Profile.UserName: <%=Profile.UserName %>
    %>`. As you can see, the last part is "repeated". When there are no server side code blocks in it, it works OK. Do you know a workaround for that? By the way, another interesting thing I experienced is that this macro is relatively "slow", which I didn't expect... :)
    – Sk8erPeter May 07 '12 at 13:49
  • 6
    After Feb 2014 macros are disabled for security reasons. Scroll down and see MasterHD's answer for the workaround to get Wael's method to keep working even after the security update. – MasterHD Feb 19 '14 at 02:16
  • please update this answer to include http://visualstudiogallery.msdn.microsoft.com/830a6482-3b8f-41a8-97b5-b9c581e5ad8b – Anders M. Sep 29 '14 at 12:21
  • Security reasons... [UNPRINTABLE] Anyway Ben's answer below works fine without screwing around in the registry. – ggb667 Nov 11 '14 at 21:23
  • 4
    i find Ctrl C + Ctrl V to be limiting in cases where i have already copied something onto the clipboard, and would like to duplicate a line before i paste. – sawe May 02 '16 at 07:16
  • `Ctrl + C` will copy the line if nothing is selected. AWESOME! – Jim Aho May 13 '16 at 11:14
  • 3
    Why on earth is it *so hard* to implement a duplicate action or keybinding which most of the other editors do very efficiently and intuitively. :/ – Nasik Shafeek Aug 12 '16 at 16:51
  • 1
    why its needed. I copied smth in other tab, i come to specific line in this tab, i duplicate line and then use CTRL + V to paste some code in. Otherwise i have to go and recopy other code part again... – Augustas Feb 01 '17 at 13:17
  • Macros only seem to be in js – ss7 Feb 19 '17 at 09:56
  • Guys, better answer is below from Vazgen Torosyan, scroll down. – Manohar Reddy Poreddy Oct 01 '17 at 03:00
  • In VS 2022 it seems to be Ctrl + shift + D – Ray1618 Jan 20 '22 at 23:41
  • Ctrl+D is not the default in VS2019 on any of the PCs I have installed it on. I successfully use ewwink's solution below (Tools / Options / Environment / Keyboard / Edit.Duplicate). – Skyfish Feb 14 '22 at 10:08
  • In VS 2022, `Ctrl` + `E`, `Ctrl` + `V`, duplicate on a new line, where as the posted solution `Ctrl` + `E`, `V` does not. – Middle Jul 13 '22 at 19:28
  • VS2019 v16.11.4 does not work ```Ctrl + D```. The correct is ```Ctrl + E, V``` – Jeferson Tenorio Sep 30 '22 at 08:14
145

There's a free extension you can download here that lets you duplicate lines without replacing the clipboard contents.

By default its bound to Alt + D, but you can change it to anything you want by going to Tools->Options->Environment->Keyboard. Type "Duplicate" in the search box and look for "Edit.DuplicateSelection" and edit the shortcut to whatever you want. I prefer Ctrl + D to be consistent with other editors.

Ben
  • 2,493
  • 1
  • 18
  • 10
  • 23
    This is the real answer you're looking for, everything else posted here is clever, but just not what was asked for. – Remco Boom Aug 14 '13 at 08:35
  • 9
    `Edit.DuplicateSelection` does not appear to be present in VSE 2013. Or anything else with the term _duplicate_ in fact. – ᴍᴀᴛᴛ ʙᴀᴋᴇʀ Apr 04 '14 at 10:32
  • 1
    http://visualstudiogallery.msdn.microsoft.com/830a6482-3b8f-41a8-97b5-b9c581e5ad8b works for vse2013 – Anders M. Sep 29 '14 at 12:16
  • 2
    Matthew, you have to click the HERE link and install the extension. THEN you have to close visual studio and reopen it. THEN you have to go to Tools ==> Options ==> Environment ==> Keyboard and THEN you have to type Duplicate and you will see it. Then you can press F4 so it acts like QEDIT or whatever you want and life will be good. – ggb667 Nov 11 '14 at 21:20
  • Even if it's a bit painful to have to install another tool, this one does the job and does it well. Thanks ! – Sbu Nov 26 '14 at 09:24
  • How do you stop CTRL + D from duplicating a line on the existing same line ? It doesn't put it on a new line for me ? – Aindriú Aug 24 '16 at 10:37
  • To me, it is super weird that it is a part of VS Code and not part of Visual Studio... Probably cuz they don't want to mess it up for people who have been VS for years but c'mon... – Tackgnol Dec 30 '17 at 16:18
  • @dvdmn the extension isn‘t needed anymore with VS17 because Microsoft finally included it. Command name is `Edit.Duplicate` and default shortcut is Ctrl+E, Ctrl+V – bugybunny Nov 16 '18 at 10:00
  • On Linux, Alt + D opens the debug menu. Ctrl + D is "add next occurrence" – kurdtpage Apr 26 '19 at 10:04
101

It's simple Ctrl + C ; Ctrl + V , check this link. As long as you don't select any text, this will duplicate the line the cursor is over when you press Ctrl+C.

Kevin
  • 14,655
  • 24
  • 74
  • 124
cand
  • 2,615
  • 4
  • 18
  • 13
  • 170
    There are numerous occasions where you don't want to go through the clip board, for example if you want to duplicate a line and then replace some content in it with something you have in the clip board. – Effata May 28 '10 at 08:21
  • 7
    Sure, but the question asked for a shortcut, not for a general solution for text editing, so I think that for simple purposes it's enough (at least it was in my case). – cand May 28 '10 at 10:28
  • 4
    thanks, but I was expecting something like Ctrl+j in Edit Plus or Crtl+D in Notepad++ ... is there any in VS2008 or in VS2010 – Posto Jun 08 '10 at 16:38
  • 2
    I've only found this one. However it's not that bad - of course easier would be to use ctrl+D, but if You want to duplicate 1 line in 100 copies You can do it using ctrl+c (without need to select anything, just put command prompt over wanted line) + 100 times ctrl+v. It's only one set of keystrokes more than ctrl+d solution. It can be more problematic if You want to do more complex duplication. – cand Jun 21 '10 at 15:27
  • @Mason240 That was my initial reaction as well to the quoted part in the accepted answer however the additional information 'As long as you don't select any text, this will duplicate the line the cursor is over...' makes this an ideal solution in my case. – RyanfaeScotland Aug 19 '14 at 09:57
  • I think this DOES do what he wants but it screws up the clipboard. A better solution is the one Ben proposed. – ggb667 Nov 11 '14 at 21:22
  • One addendum to this is that you can use the visual studio clipboard ring afterwards to get to a previously copied item. Ctrl+Shift+V. – Error 454 Dec 10 '14 at 20:46
  • This just plain does not work "as long as no text is selected". Nope, it just copies nothing thus never changing whats in the clipboard and then pasting in whatever was there. Stupid this has 76 upvotes. – user9993 Apr 07 '17 at 13:00
  • That's answering how to use the clipboard, not how to duplicate a line. What if you want to duplicate a line without replacing clipboard content? – Antony Booth Nov 16 '17 at 16:23
  • _If you don't want to override current content of the clipboard and still need to copy/paste_: just select the text, press control and drag and drop the text where you need it to be copied. – chviLadislav Jun 26 '19 at 07:53
86

Ctrl + C + V works for me on VS2012 with no extension.

Rahil Wazir
  • 10,007
  • 11
  • 42
  • 64
nGoline
  • 968
  • 6
  • 4
34

In Visual Studio 2013 you can use Ctrl+C+V

Nicofisi
  • 1,083
  • 1
  • 15
  • 27
Vazgen Torosyan
  • 1,255
  • 1
  • 12
  • 26
33

Ctrl + D works for me in VS2012 with Resharper. It's Resharper's hot key.

Mwiza
  • 7,780
  • 3
  • 46
  • 42
sawe
  • 1,141
  • 14
  • 24
  • 11
    no its not, only realised that after posting, but it is a Resharper shortcut. and if one has resharper installed, then this could help. – sawe Apr 02 '13 at 13:54
  • 1
    I have resharper, and didn't know that shortcut! Thanks. – DanO Oct 28 '13 at 22:48
  • This is the default shortcut if you are using Resharper's "Resharper 2.x or IntelliJ IDEA" keyboard scheme. Resharper has you select the keyboard mapping during the install. "Visual Studio" keyboard scheme is one of the choices. If you pick "Visual Studio" keyboard scheme, then Ctrl+D will be mapped to something else. – GeoMac Apr 28 '17 at 12:44
  • That's an answer to a ReSharper question. – Antony Booth Nov 16 '17 at 16:22
  • Note that this also works when multiple lines are selected, i.e. you can duplicate a whole bunch of code, not just one line. Downside of course being that resharper isn't free (but it seems the .Net world is used to that more than the Java world I come from). – Amos M. Carpenter Jan 19 '18 at 05:31
23

Here's a macro based on the one in the link posted by Wael, but improved in the following areas:

  • slightly shorter
  • slightly faster
  • comments :)
  • behaves for lines starting with "///"
  • can be undone with a single undo
Imports System
Imports EnvDTE
Imports EnvDTE80

Public Module Module1

    Sub DuplicateLine()
        Dim sel As TextSelection = DTE.ActiveDocument.Selection
        sel.StartOfLine(0) '' move to start
        sel.EndOfLine(True) '' select to end
        Dim line As String = sel.Text
        sel.EndOfLine(False) '' move to end
        sel.Insert(ControlChars.NewLine + line, vsInsertFlags.vsInsertFlagsCollapseToEnd)
    End Sub

End Module
phuclv
  • 37,963
  • 15
  • 156
  • 475
Mark Foreman
  • 2,190
  • 18
  • 16
  • 1
    Yeah this one actually works, the one in the accepted answer was copying random stuff into the new line. Nice work, thanks! – zuallauz Jul 27 '12 at 02:06
  • I did not find the Macros option in VS 2010 Express, can this be implemented there? – Joel Peltonen Apr 26 '13 at 07:53
  • 1
    After Feb 2014 macros are disabled for security reasons. Scroll down and see MasterHD's answer for the workaround to get Mark's method to keep working even after the security update. – MasterHD Feb 19 '14 at 02:17
15

In Visual studio 2017 and maybe other version No need Macro or Extension,

  1. Go to Tools > Options > Environment > Keyboards
  2. Under Show commands containing: write Edit.Duplicate
  3. Place cursor to Press shortcut keys: and press Ctrl + D and click Assign button
  4. click OK to save your new keyboard shortcut

enter image description here

ewwink
  • 18,382
  • 2
  • 44
  • 54
  • This answer helped me but in a different way. I have VS 2022 and I had Resharper trial installed and it expired. After I uninstalled it, all my macros were wrong or non-existent. Every field was gray from this step-by-step after I selected Edit.Duplicate from that list. I had to press the Reset button and after that, change it directly from the "Shortcuts for selected command" field. – Eduard Jul 01 '22 at 11:38
11

If you like eclipse style line (or block) duplicating using CTRL+ALT+UP or CTRL+UP+DOWN, below I post macros for this purpose:

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports System.Diagnostics

Public Module DuplicateLineModule
    Sub DuplicateLineDown()
        Dim selection As TextSelection = DTE.ActiveDocument.Selection
        Dim lineNumber As Integer
        Dim line As String

        If selection.IsEmpty Then
            selection.StartOfLine(0)
            selection.EndOfLine(True)
        Else
            Dim top As Integer = selection.TopLine
            Dim bottom As Integer = selection.BottomLine

            selection.MoveToDisplayColumn(top, 0)
            selection.StartOfLine(0)

            selection.MoveToDisplayColumn(bottom, 0, True)
            selection.EndOfLine(True)
        End If

        lineNumber = selection.TopLine
        line = selection.Text

        selection.MoveToDisplayColumn(selection.BottomLine, 0)
        selection.EndOfLine()
        selection.Insert(vbNewLine & line)
    End Sub
    Sub DuplicateLineUp()
        Dim selection As TextSelection = DTE.ActiveDocument.Selection
        Dim lineNumber As Integer
        Dim line As String

        If selection.IsEmpty Then
            selection.StartOfLine(0)
            selection.EndOfLine(True)
        Else
            Dim top As Integer = selection.TopLine
            Dim bottom As Integer = selection.BottomLine

            selection.MoveToDisplayColumn(top, 0)
            selection.StartOfLine(0)

            selection.MoveToDisplayColumn(bottom, 0, True)
            selection.EndOfLine(True)
        End If

        lineNumber = selection.BottomLine
        line = selection.Text

        selection.MoveToDisplayColumn(selection.BottomLine, 0)
        selection.Insert(vbNewLine & line)
        selection.MoveToDisplayColumn(lineNumber, 0)
    End Sub
End Module
phuclv
  • 37,963
  • 15
  • 156
  • 475
Krzysztof
  • 15,900
  • 2
  • 46
  • 76
11

In visual studio code (WebMatrix):

Copy Lines Down: Shift + Alt + down

Copy Lines Up: Shift + Alt + up

Delete Lines: Ctrl + Shift + k

Milad Ghiravani
  • 1,625
  • 23
  • 43
  • 2
    This is the best answer so far; it will even allow you to duplicate a full block of code -if so you desire- just by selecting multiple lines. Tested in Visual Studio Code 1.7.2 – Victor Barrantes Dec 01 '16 at 05:53
10

Why so many long drawn out methods to accomplish something so simple? It takes less than a minute to download and install the extension from Microsoft. The page says that it will bind it to ALT+D by default, but for me it bound it to CTRL+D automatically in Visual Studio Community 2015 without any changes.

Here's the link to download the extension from Microsoft.com.

Mwiza
  • 7,780
  • 3
  • 46
  • 42
Daniel
  • 145
  • 1
  • 13
  • The question is about Visual Studio 2008, and not 2015 :) – marsaldev Nov 04 '16 at 12:30
  • It should be noted that this extension duplicates the selected lines, and not the selection. But it's still useful. – ANeves May 04 '17 at 18:10
  • This one is most useful for me because I wanted a solution that did not replace what I had in the clipboard. This extension is exactly what I was looking for. And according to the extension author, this currently works for Visual Studio 2012, 2013, 2015, and 2017. – Mark Mar 16 '18 at 12:42
8

As I can't use Macros in my Visual Studio 2013 I found a Visual Studio Plugin (I use it in 2012 and 2013). Duplicate Selection duplicates selections and whole Lines - they only need to be partial selected. The standard shortcut is ALT + D.

Mwiza
  • 7,780
  • 3
  • 46
  • 42
Lebewesen
  • 147
  • 1
  • 8
7

While I realize this is not a keyboard shortcut, I figured I would add this, as it does not require the usage of the clipboard and might help some people.

Highlight the row you want to duplicate. Press control, mouse click the highlighted text, and drag to where you want to go to. It will duplicate the highlighted text.

Warty
  • 7,237
  • 1
  • 31
  • 49
  • Achieves the same result with built-in functionality! And the question only asked for a shortcut - not necessarily a keyboard shortcut! Still, would be more awesome if the mouse didn't have to be involved. – DanO Oct 28 '13 at 22:46
5

I don't know if this exists in Visual Studio 2008 but in Visual Studio 2010+ you can easily do this by:

Don't select anything, then press Ctrl + C And then (without doing anything else) Ctrl + V

Alireza Noori
  • 14,961
  • 30
  • 95
  • 179
5

for Visual Studio 2012, 2013, 2015, 2017 follow the link and download the extension

https://marketplace.visualstudio.com/items?itemName=ctlajoie.DuplicateSelection

Now go into Tools > Options > Keyboard, and type "Duplicate" in the search box (the full command string is "Edit.DuplicateSelection"). Here you can bind it to any shortcut in the same way you would for any other command.

Kalyan Halder
  • 1,485
  • 24
  • 28
4

I've been using the macro that Wael posted: Duplicate line command for Visual Studio, but it stopped working a week ago, I assumed because of a Windows update. And I was correct, as of February 2014, Macros have been disabled in VS2010 (and 2008 apparently).

To fix this you'll either have to uninstall the security updates, or add one line of code into the config files as shown here.

On a 64-bit Windows machine default paths to these files are:

  • C:\Program Files (x86)\Common Files\Microsoft Shared\VSA\9.0\VsaEnv\vsaenv10.exe.config
  • C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe.config

    ...
    <configuration>
        <runtime>
            <AllowDComReflection enabled="true"/>
            ...
    

    editor screenshot

You MUST run your text editor with admin rights or it won't work! Hopefully this helps anyone else who suddenly has their macro functionality pulled out from underneath them.

MasterHD
  • 2,264
  • 1
  • 32
  • 41
3

In visual studio 2008 you can use CTRL + C + V

Mwiza
  • 7,780
  • 3
  • 46
  • 42
3

For those still viewing this question on Visual Studio post-2008, a real Edit.Duplicate has been added:

  • CTRL+E, V
  • CTRL+D (VS 2017 15.6+)
icanfathom
  • 291
  • 4
  • 11
3

For Visual Studio Code 2019:

Edit menu keyboard shortcuts with: ctrl+k and ctrl+s

Edit "Copy Line Down" (Shift + Alt + DownArrow) to your your own shortcut.

You can find it, with the command ID: editor.action.copyLinesDownAction

For me, It's ctrl+d

Uruca
  • 71
  • 1
  • 7
2

Just put your mouse on the line to copy and do CTRL+C ,afterwards CTRL+V on the same line. Works like magic :-)

Mwiza
  • 7,780
  • 3
  • 46
  • 42
2

Ctrl + D is a new shortcut introduced in VS 2017 v15.6 that seems to do the exact thing that Ctrl + E, V

Ctrl + D will duplicate the line the cursor is in and insert it right below the line in focus. If you’d like to duplicate a specific set of code, simply select the portion of code you want to duplicate before invoking the duplicate code command.

It won't affect your clipboard

Source

Kautsky Lozano
  • 722
  • 12
  • 21
2

if you have a macos version, cmd+shift+D can make the job for you

1

I use application link:AutoHotkey with below code saved in CommentDuplikateSaveClipboard.ahk file. You can edit/remove shortcuts it is easy.
I have link to this file "Shortcut to CommentDuplikateSaveClipboard.ahk" in Autostart in windows.
This script protect your clipboard.
If you are more curious you would add shortcuts to thisable/enable script.
I sometimes use very impressive Multi Clipboard script to easy handle with many clips saved on disk and use with CTRL+C,X,V to copy,paste,cut,next,previous,delete this,delete all.

;CommentDuplikateSaveClipboard.ahk

!c:: ; Alt+C === Duplicate Line
^d:: ; Ctrl+D
ClipSaved := ClipboardAll
Send, {END}{SHIFTDOWN}{HOME}{SHIFTUP}{CTRLDOWN}c{CTRLUP}{END}{ENTER}{CTRLDOWN}v{CTRLUP}{HOME}
Clipboard := ClipSaved
ClipSaved =
return

!x:: ; Alt+X === Comment Duplicate Line
ClipSaved := ClipboardAll
Send, {END}{SHIFTDOWN}{HOME}{SHIFTUP}{CTRLDOWN}c{CTRLUP}{LEFT}//{END}{ENTER}{CTRLDOWN}v{CTRLUP}{HOME}
Clipboard := ClipSaved
ClipSaved =
return

!z:: ; Alt+Z === Del uncomment  Line
ClipSaved := ClipboardAll
Send, {END}{SHIFTDOWN}{UP}{END}{SHIFTUP}{DEL}{HOME}{DEL}{DEL}
Clipboard := ClipSaved
ClipSaved =
return

!d:: ; Alt+D === Delete line
Send, {END}{SHIFTDOWN}{UP}{END}{SHIFTUP}{DEL}
return

!s:: ; Alt+S === Swap lines
ClipSaved := ClipboardAll
Send, {END}{SHIFTDOWN}{UP}{END}{SHIFTUP}{CTRLDOWN}x{CTRLUP}{UP}{END}{CTRLDOWN}v{CTRLUP}{HOME}
Clipboard := ClipSaved
ClipSaved =
return

!a:: ; Alt+A === Comment this line, uncomment above
Send, {END}{HOME}//{UP}{HOME}{DEL}{DEL}
return
Mwiza
  • 7,780
  • 3
  • 46
  • 42
MrHIDEn
  • 1,723
  • 1
  • 25
  • 23
1

In Visual Studio 2010 you copy the entire line the cursor is on with CTRL + INSERT then you can use Ctrl + V or SHIFT + INSERT to paste it.

Mwiza
  • 7,780
  • 3
  • 46
  • 42
Crackerjack
  • 2,154
  • 3
  • 28
  • 36
1

VS 2017 its Ctrl + D or Ctrl + C ; Ctrl + V they both work for me.

1

The command you want is Edit.Duplicate. It is mapped to CtrlE, CtrlV. This will not overwrite your clipboard.

HaveSpacesuit
  • 3,572
  • 6
  • 40
  • 59
1

http://www.jetbrains.com/resharper/

My story: started working in a new company, never used Visual Studio before. One of the first things - how to duplicate line. After setting up macro ReSharper told me: would you like to substitute my shortcut which was: "duplicate text" :)

Mars Robertson
  • 12,673
  • 11
  • 68
  • 89
0

Not an answer, just a useful addition: As a freebie, I just invented (well... ehm... adjusted the code posted by Lolo) a RemoveLineOrBlock macro. Enjoy!

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics

Public Module RemoveLineOrBlock

    Sub RemoveLineOrBlock()
        Dim selection As TextSelection = DTE.ActiveDocument.Selection
        Dim lineNumber As Integer
        Dim line As String

        If selection.IsEmpty Then
            selection.StartOfLine(0)
            selection.EndOfLine(True)
        Else
            Dim top As Integer = selection.TopLine
            Dim bottom As Integer = selection.BottomLine

            selection.MoveToDisplayColumn(top, 0)
            selection.StartOfLine(0)

            selection.MoveToDisplayColumn(bottom, 0, True)
            selection.EndOfLine(True)
        End If

        selection.LineDown(True)
        selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstColumn,True)

        selection.Delete()

        selection.MoveToDisplayColumn(selection.BottomLine, 0)
        selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText)

    End Sub

End Module
phuclv
  • 37,963
  • 15
  • 156
  • 475
Peter Perháč
  • 20,434
  • 21
  • 120
  • 152
0

in VS2019 and also in VS2017 you can select Tools->Options->Keyboard and you can choose in the scheme drop-down Resharper (Visual Studio) option, and you will get a mapping like if you were using Resharper, in this case Ctrl + D will do the trick for duplicating the line. Anyways, based on the documentation this should be out of the gate in Visual Studio 2017 Version 15.8 or greater

ddieppa
  • 5,866
  • 7
  • 30
  • 40
0

On Linux Mint, you can do;

**Ctrl + Alt + Shift + 2** => *Duplicate up*
**Ctrl + Alt + Shift + 8** => *Duplicate down*
-1

Visual Studio Code : May 2020 (version 1.46) Shift + UpArrow/DownArrow : To Duplicate the line of code

Nike
  • 97
  • 6
-4

For visual studio 2010, try using these commands for quick line duplication (uses clipboard):

  • Click on the line you want to copy. Ctrl + C will copy that line.

  • Then press Ctrl + Shift + Enter to insert a blank below insertion point

    (Alternatively use Ctrl + Enter to insert a blank line above the insertion point.)

  • Then simply use Ctrl + V to paste the line.

Jasper
  • 2,166
  • 4
  • 30
  • 50
protoss1210
  • 162
  • 1
  • 6