Hvordan kopierer jeg en kodelinje med Microsoft's Visual Studio Code og flytter den op og ned? (Svarende til Sublime's cmd+shift+d adfærd)
Det er en funktion, som jeg bruger konstant, og jeg har svært ved at bruge Visual Studio Code uden den.
De kommandoer, du leder efter, er editor.action.copyLinesDownAction
og editor.action.copyLinesUpAction
.
Du kan se de tilhørende tastaturbindinger ved at vælge: File > Preferences > Keyboard Shortcuts
Windows:
Shift+Alt+Down og Shift+Alt+Up
Mac:
Shift+Option+Ned og Shift+OptionOpOp
Linux:
Ctrl+Shift+Alt+Ned og Ctrl+Shift+Alt+Up
(Måske skal du bruge numpad Down og Up til Linux)
Desuden kan kommandoerne editor.action.moveLinesUpAction
og editor.action.moveLinesDownAction
er dem til at flytte linjer, og de er bundet til Alt+Down og Alt+Up på Windows og Mac og Ctrl+Down og Ctrl+Up på Linux.
Du kan finde tastaturgenveje fra
File > Preferences > Keyboard Shortcuts
Standard tastaturgenveje er,
Kopier linjer nedad handling : shift+alt+down
Kopiering af linjer opad handling : shift+alt+opad
Flytte linjer opad handling : alt+op
Flytte linjer nedad handling : alt+ned
Eller du kan tilsidesætte tastaturgenvejene fra
File > Preferences > Keyboard Shortcuts
Og redigere keybindings.json
.
Eksempel:
[
{
"key": "ctrl+d",
"command": "editor.action.copyLinesDownAction",
"when": "editorTextFocus"
},
{
"key": "ctrl+shift+up",
"command": "editor.action.moveLinesUpAction",
"when": "editorTextFocus"
},
{
"key": "ctrl+shift+down",
"command": "editor.action.moveLinesDownAction",
"when": "editorTextFocus"
}
]
Prøv ALT+SHIFT+UP/DOWN
Det virkede for mig!