Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2017 - How do I duplicate the current line?

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?

like image 562
J.Doe Avatar asked Jul 16 '17 15:07

J.Doe


3 Answers

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";
like image 155
Robin de Klerk Avatar answered Oct 17 '22 05:10

Robin de Klerk


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.

like image 15
JeffR Avatar answered Oct 17 '22 05:10

JeffR


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

like image 8
J.Doe Avatar answered Oct 17 '22 07:10

J.Doe