Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code - duplicate selection ONLY

There is a solution on how to duplicate a line. But how do I duplicate the selection? Like in Notepad++.

like image 349
yodalr Avatar asked Feb 07 '17 10:02

yodalr


2 Answers

This extension worked for me:

https://marketplace.visualstudio.com/items?itemName=lafe.contextualduplicate

I then opened up my Keyboard Shortcuts to assign a memorable binding. In my case, I used <SHIFT><COMMAND>-D so it behaves just like Sublime Text.

like image 133
Eric Constantinides Avatar answered Sep 21 '22 17:09

Eric Constantinides


There is now a dedicated command, with VSCode 1.40 (Oct. 2019):

Duplicate selection

We have added a new action named Duplicate Selection.

  • When executed, the current selection will be duplicated and the result will be selected.
  • When there is no selection, the current line will be duplicated, all without writing to the system clipboard.

You can associate a keyboard shortcut to that command.

like image 42
VonC Avatar answered Sep 24 '22 17:09

VonC