I have 4 lines like this in VS Code:
1 line;
2 line;
3 line;
4 line;
Does VS Code have a shortcut that can quickly compact 4 lines to 1 line like this:
1 line; 2 line; 3 line; 4 line;
Select your code => F1 => "Join Lines"
You can also create a keyboard shortcut for this command editor.action.joinLines
Default shortcut on Mac is Ctrl+J
F1, type join lines, click :gear-icon, press & hold ctrl and press and release sequence: K + K. In the new window I recommend setting the keybinding to press & hold ctrl and press and release sequence: J + L. (ctrl + j, shift+ctrl+j, ctrl + l are all already set). Chorded keybinds do not require that you let go of ctrl between the two combinations - but you can; it makes no difference.Ctrl+J on Windows is Toggle Panel. Unless you installed a keymaps extension like Sublime keymap.cmd + ctrl + shift + sI also had same issue and solved it. If you use Prettier, try it as below.
Settings -> Prettier.printWidth"
The default value is 80. If you change this value higher than 80.
Adding to Alex's answer:
A better option would be to bind a shortcut key to "Join Lines", fo i.e. Ctrl + Shift + U.
For anyone who doesn't want to do Shift + Ctrl + P and manually selecting "Join Lines" every time they want to use this feature, just do Shift + Ctrl + p once and click Open Keyboard Shortcuts (JSON), then just paste this in:
{
"key": "shift+cmd+l", // hotkey
"command": "editor.action.joinLines", // action to perform
"when": "editorTextFocus && !editorReadonly" // if conditions match
}
Warning
Don't forget the change "cmd" to "ctrl" if you don't have command key
cmd is only available for macOS. Use ctrl for Windows and Linux.Or you could use these two in vs code.
Fold multiple lines: ctrl + shift + [
Unfold multiple lines: ctrl + shift + ]
I prefer these because I want to use prettier as well.