Reputation: 69
I already found that the "command": "editor.action.duplicateSelection"
will duplicate the selection right next to it.
I want to duplicate the selected text to a new line. The selection may not be the entire line.
Upvotes: 2
Views: 725
Reputation: 181419
If you are talking about a selection that is less than the entire line, there is no built-in way to duplicate selected text to the next line. It can be done with the runCommands
command which enables you to run multiple commands at once, i.e., no extension is needed.
Try this keybinding (in your keybindings.json
):
{
"key": "alt+i", // whatever keybinding you want
"command": "runCommands",
"args": {
"commands": [
"editor.action.clipboardCopyAction",
"editor.action.insertLineAfter",
"editor.action.clipboardPasteAction",
{ // to add text after the selection
"command": "type", // you could also put this before the paste command
"args": { "text": " myText here after paste " }
}
]
}
}
That will copy the selected text, insert a blank line after it and paste that text there. Demo:
Demo with adding static text to the duplicated text:
Upvotes: 1
Reputation: 118
Click File > Preferences > Keyboard Shortcuts:
Look for the Copy Line Down keyboard shortcut.
Upvotes: 0