11

Is there any way to duplicate a line of code with a keyboard shortcut in the new Visual Studio 11 ?
I had a little macro set up in the previous version but according to this article, the macros are discontinued.

Is there any workaround I could use?

Michael Mullany
  • 30,283
  • 6
  • 81
  • 105
ScarletAmaranth
  • 5,065
  • 2
  • 23
  • 34
  • 5
    The same question was asked [before](http://stackoverflow.com/questions/2279000/visual-studio-short-cut-key-duplicate-line). Somebody can find more answers there :) – Andron Feb 11 '15 at 10:50

2 Answers2

10

Check this extension:

Duplicate the line without touching the clipboard (as Notepad++ does).

nergeia
  • 894
  • 13
  • 20
  • This is a great option, if installing a plugin is an option. – gcoulby Aug 04 '15 at 07:29
  • Yes! This should be the accepted answer. Thanks to [Visual Studio Community Edition](https://www.visualstudio.com/en-us/products/visual-studio-community-vs.aspx), installing an extension should be an option for everybody, also us freebees :). Microsoft is really opening up because in their new cross platform [Visual Studio Code](https://code.visualstudio.com/) editor there is Shift+Alt+down arrow for this. I expect this shortkey to hit 'full VS' as well in the near future. – Bart Oct 21 '15 at 17:46
  • Awesome Plugin, thank you . – Mohamad Al Asmar Oct 27 '16 at 12:24
6

Ctrl+C and Ctrl+V

Try it...

KMoraz
  • 14,004
  • 3
  • 49
  • 82
  • 2
    Did you define yourself a nice cup of #exclude :) ? Works like a charm but having the explication turned off, I'm going to claim that i typed "shortcut" which implies that the amount of "shortcutting" sequences i would like to use is limited to exactly one. – ScarletAmaranth Mar 27 '12 at 19:21
  • 5
    "not supported" will be a better answer I assume – KMoraz Mar 27 '12 at 20:18
  • 2
    I think this is a valid answer since most people don't know that ctrl-C at the start of a line copies the whole line without your needing to select it. I use this "chorded" shortcut as a single gesture all the time. I don't think "copy then paste" I think "duplicate the line" and that's how I do it. If I were to write a macro, I would have it duplicate the line and comment out one of the two - something else I do quite a lot. – Kate Gregory Apr 01 '12 at 16:41
  • 9
    What is the interest of duplicate line if it delete clipboard content ? Duplicate line is used when you want to copy a line and change one var by the one you have in the clipboard. – bokan Oct 23 '12 at 08:11
  • This solves the problem sure, but it wipes the clipboard, and requires FOUR key presses, and it can't be rebound to fewer :-( – Orion Edwards Jul 07 '13 at 23:48
  • 2
    @KateGregory You don't have to position the cursor at the start of the line, anywhere in the line is fine. – user247702 Oct 25 '13 at 12:44
  • @Stijn interesting, I just confirmed this in VS 2013. When I learned the trick (which would be VC 6 or earlier) you had to be at the start of the line. Thanks! – Kate Gregory Oct 25 '13 at 12:48
  • did always do `end, shift home, ctrl c, ctrl v` till try this tip. Thanks! – Luke Oct 22 '14 at 15:29
  • I was about to dismiss this thinking it was some cocky remark, but it works; however, it does wipe the clipboard, which is not always ideal. So I would say that nergeia's answer is better ...if installing a plugin is an option. – gcoulby Aug 04 '15 at 07:29
  • Easy line duplication is one of the biggest reason of what was making me to paying for Resharper. Knowing this way of copying might change my mind. Thank you so much! – Vildan Sep 16 '16 at 18:25
  • 1
    It is overriding a clipboard.. – Jakub Kučera Oct 17 '16 at 08:41