I know the shortcut key that deletes a line (CTRL + SHIFT + K) but I don’t want this kind of behavior. Instead, when I press a keyboard shortcut I want it to clear the string of code inside the current line where my cursor is at and not move after the next line of code
For instance when I put my cursor on the 3rd line and I perform a keyboard shortcut:
1
2 console.log('Text'); // Cursor here
3 console.log('2nd Text);
4
It should only leave it blank and only clear the line of code but remain on the same line:
1
2 // Newline/Whitespace Cursor is also here
3 console.log('2nd Text); // This does not move to the 2nd line.
4
Scouring the internet, the only search results I get is how to delete the line(CTRL+SHIFT+K) but not clear it.
2
Answers
This may be off topic, but it is possible with a compound keyboard shortcut you need to define yourself.
Details here: https://code.visualstudio.com/docs/getstarted/keybindings
The key is
runCommands
which lets you run multiple editor commands.This example does something similar, but not exactly what you want.
I think what you want is more like
It looks like you want this keybinding:
That will move the cursor to the end of the line and then delete everything on the line leaving the cursor on that same line at column 1.
This series of commands will preserve any leading whitespace on that line: