Using Microsoft\'s Visual Studio Code, how do I duplicate a line of code and then move it up and down? (Similar to Sublime\'s cmd+shift+d be
You can find keyboard shortcuts from
File > Preferences > Keyboard Shortcuts
Default Keyboard Shortcuts are,
Copy Lines Down Action : shift+alt+down
Copy Lines Up Action : shift+alt+up
Move Lines Up Action : alt+up
Move Lines Down Action : alt+down
Or you can override the keyboard shortcuts from
File > Preferences > Keyboard Shortcuts
And editing the keybindings.json
Example:
[
{
"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"
}
]
For Windows :
To Copy Up - shift+alt+up
To Copy Down - shift+alt+down
For mac :
To Copy Up - shift+option+up
To Copy Down - shift+option+down
For linux :
To Copy Up - ctrl+shift+alt+8
To Copy Down - ctrl+shift+alt+2
Note : You may change your keyboard shortcuts keybinding for visual studio code by pressing ctrl+shift+p, then type open keyboard shortcut in the pallet and then hit enter so new file will be opened (Key board shortcut file) you can see all the shortcuts over their and can change keybindings by clicking twice over the respective keybinding and then by entering your own keybinding, finally hit enter.
Hope this will help somebody!
Simply go to the file -> preferences -> keyboard shortcuts There you can change any shortcut you like. search for duplicate and change it to whatever you always use in other editors. I changed to ctrl + D
You could install IntelliJ IDEA Keybindings to keep using almost all the keyboard shortcuts as you did in Webstorm/Phpstorm.
So,
Also, here is a list of recommended VS Code extensions that will make your transition from WebStorm/Phpstorm much easier.
For Fedora 29 workstation (Gnome 3.30.2) and Ubuntu users.
Unbind unnecessary left/right workspace keyboard combinations, list them by terminal
$ gsettings list-recursively | grep -E "org.gnome.desktop.wm.keybindings move-to-workspace-|org.gnome.desktop.wm.keybindings switch-to-workspace-"
Unbind them
$ gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-left "[]"
$ gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-right "[]"
$ gsettings set org.gnome.desktop.wm.keybindings move-to-workspace-left "[]"
$ gsettings set org.gnome.desktop.wm.keybindings move-to-workspace-right "[]"
Reset duplicate shortcuts
They can be easily reset to work with only one shortcut in Settings>Devices>Keyboard
Only type again Super+PgUp for "Move to workspace above" as an example.
Now with less duplicate shortcuts in fedora29 all vscode shortcuts for linux must work fine
In VScode, they call this Copy Line Up
and Copy Line Down
From the menu, go to:
File > Preferences > Keyboard Shortcuts
Check already assigned keyboard shortcut for this, or adjust yours.
Sometimes the default assigned shortcut may not work, mostly because of OS.
In my Ubuntu, I adjusted this to: Ctrl+Shift+D