10

I want to duplicate the current line to a new line below it. I found this post but I can't find the option they're talking about (editor.action.copyLinesDownAction) in options > keyboard.

How do we do this in 2017?

J.Doe
  • 643
  • 1
  • 6
  • 16
  • 1
    Is CTRL + D not working? – Cihan Yakar Jul 16 '17 at 15:39
  • No sir. Doesn't seem to do anything. – J.Doe Jul 16 '17 at 15:42
  • 1
    You can try reset your settings `Tools -> Import and Export Settings -> Reset all setting` (Do not forget to take a backup of your current settings) – Cihan Yakar Jul 16 '17 at 15:46
  • Tried that too, didn't work. I'm in Microsoft Visual Studio, not Visual Studio Code if that helps. Also I found an extension that does it for me. Found it in the search bar in `...extensions and plugins`. I just searched "duplicate" and installed the first one, bound it to `alt+d` and it's all good now : ). Thanks for your help though – J.Doe Jul 16 '17 at 15:50
  • I've even assigned "Edit.Duplicate" command to Ctrl+D (Global) and it still doesn't do anything - either it doesn't work or it does something else I'm not clear about – PandaWood Jun 21 '18 at 01:37
  • I have an install that has been upgraded several times over the years. Edit.Duplicate isn't an option in the Show Commands of Customize->Keyboard. Frustrating because on my main machine that is newer and has a fresh install the option is there and is mapped to Ctrl+D in the Text Editor. Both machines have the same version of VS installed. – jws Nov 18 '18 at 14:11

3 Answers3

15

I'm not sure if this is a new feature from one of the updates but the following key combination works for me in VS 2017 (v 15.7.3):

Ctrl + E,V

This duplicates the current line that the cursor is on or it will duplicate any selected text and you won't lose the contents stored in the clipboard.
I have not tried remapping that command to a different key combination.

JeffR
  • 1,733
  • 1
  • 15
  • 18
8

Found an extension that does this right here. Hope this helps people.

J.Doe
  • 643
  • 1
  • 6
  • 16
7

Click anywhere on the line you want to duplicate (do not select the text), press Ctrl+C, and press Ctrl+V to create the duplicated line. You can duplicate that line to anywhere now, not just to next line and it will insert the line above the selected line. e.g.

427    string foo = "text";
428
429        string bar = "other";

Click anywhere on line 427 and press Ctrl+C. Click on line 429 and press Ctrl+V

427    string foo = "text";
428
429    string foo = "text";
430        string bar = "other";