In IntelliJ IDEA and other JetBrains IDEs there is a setting I quite enjoy: When you delete an empty line, its cursor automatically move to the upper line, like this:
How can I assign this setting in VS Code?
In IntelliJ IDEA and other JetBrains IDEs there is a setting I quite enjoy: When you delete an empty line, its cursor automatically move to the upper line, like this:
How can I assign this setting in VS Code?
You can use editor.action.deleteLines
to delete the current line by pressing Ctrl + Shift + K.
However, your cursor will not move up after the line is deleted as you have shown in IntelliJ. I don't see a built-in option for this feature right now, but you can create your own macro to do it with the macros extension. It only takes a couple minutes to configure.
Add the following to your settings.json
file to create a macro called deleteLinesUp
that will delete the line and then move the cursor up.
"macros": {
"deleteLinesUp": [
"editor.action.deleteLines",
"cursorUp"
]
},
Open your keybindings.json
file and add the following to override Ctrl + Shift + K so it calls deleteLinesUp
instead of deleteLines
.
{
"key": "ctrl+shift+k",
"command": "macros.deleteLinesUp"
}
Now it will behave as you desire. Also, you can bind this macro to whatever key combination you want.
You want to install the Hungry Delete extension.
It changes the behavior of the backspace. When you hit backspace in a line that has none other than white space, it erases the whole line and moves the cursor up, which is the same behavior of JetBrains' editors, demonstrated in the question.
I believe you can do this without an extension. Try this keybinding (in your keybindings.json
):
{
"key": "backspace", // whatever you want, demo is with backspace
"command": "runCommands",
"args": {
"commands": [
"cursorHomeSelect", // select the entire line
"cursorHomeSelect",
{
"command": "editor.action.insertSnippet",
"args": {
"snippet": "${TM_SELECTED_TEXT/^(\\s+)$//gm}" // only match empty lines
}
},
"deleteLeft" // same as backspace
]
},
// "when": "editorTextFocus && editorLangId === json"
"when": "editorTextFocus" // MUST have this
}
I turned on the Render Whitespace
setting so can see where the "empty lines" (those with nothing but whitespace) end.
The keybinding will remove any whitespace-only lines and move the cursor to the end of the previous line.
[If the intention is to also remove all whitespace at the end of a line, the regular expression in the snippet can probably be modified to do that to.]
"when": "editorTextFocus && !editorReadonly && !editorHasSelection"
. –
Potentilla Go to File -> Preferences -> Keyboard Shortcuts
search for "Delete All Left" and "Delete All Right"
and add your keys, I prefer to use Ctrl+Shift+Backspace and Ctrl+Shift+End
© 2022 - 2024 — McMap. All rights reserved.
SHIFT
+DELETE
in IntelliJ. – Barbel