6

I'm pretty new to the VSCode editor.

When previously using atom, placing the cursor at the end of the line and pressing Ctrl+C would copy that line. Placing the cursor at the end of another line and pressing Ctrl+V would paste it below that line.

It seems that in VSCode, I can copy a line in the same way, but when I paste in the same way it places the line above the selected line. That seems pretty counter-intuitive when my cursor is at the end of the line.

Is there a setting somewhere to change this?

EDIT: I am not trying to duplicate a line where it is. I want to copy a line and paste it in a different file. But the paste function places the line above the cursor.

base12
  • 125
  • 1
  • 10
  • Does this answer your question? [How do I duplicate a line or selection within Visual Studio Code?](https://stackoverflow.com/questions/30203752/how-do-i-duplicate-a-line-or-selection-within-visual-studio-code) – nathan liang Feb 21 '22 at 06:25
  • https://stackoverflow.com/a/57025955/9938317 – rioV8 Feb 21 '22 at 13:08
  • @NathanLiang No, I'm not trying to duplicate the line, I want to paste it somewhere else – base12 Feb 21 '22 at 22:25
  • 1
    @base12masterrace Gotcha, thanks for the clarification—I've retracted my duplicate flag. Unfortunately, I'm not sure how much else you can do: if you press `Ctrl+C` with your cursor anywhere (not necessarily at the end) on the given line you'd like to copy and then press `Ctrl+V` you're always going to get it above AFAIK. It might be worth just pressing `Ctrl+Enter` which would create a new line for you without having to move your cursor to the end of the current line? I realize that's not the one step you're asking for. – nathan liang Feb 21 '22 at 23:02

1 Answers1

5

Go To Preferences -> Keyboard Shortcuts and search for "Duplicate Selection" and add whatever keybinding for it (For me it is ctrl+D).

It will duplicate your selected line to below.

gguney
  • 2,512
  • 1
  • 12
  • 26
  • 1
    I thought this was what OP was asking, but they're actually asking if there's a way to modify the default VSCode paste setting so that it defaults to outputting below a given line instead of above (even if your cursor is already at the end of the current line). Your recommendation does output a line below, but *only* if it is a duplicate of the current line. – nathan liang Feb 21 '22 at 23:05