Reputation: 3175
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;
Upvotes: 192
Views: 273940
Reputation: 139
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
Upvotes: 1
Reputation: 823
Adding to Alex's answer:
A better option would be to bind a shortcut key to "Join Lines", fo i.e. Ctrl + Shift + U.
Upvotes: 1
Reputation: 3175
It seems VS Code's "Join Lines" keyboard shortcut in macOS is ctrl + j:
Upvotes: 25
Reputation: 653
Upvotes: 4
Reputation: 184
For Windows
Just Install Sublime Keymapper extension in vscode.
Select Lines you want to be on single line then pressctrl + j
Upvotes: 1
Reputation: 153
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.
Upvotes: -1
Reputation: 47
I 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.
Upvotes: 1
Reputation: 67859
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
Upvotes: 485