microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.13k stars 29.27k forks source link

Backspace at end of empty line doesn't delete whole line and go to end of above line #42785

Open mccreeker opened 6 years ago

mccreeker commented 6 years ago

Steps to Reproduce:

  1. Create a new line of a block of multi-line code like an opening div tag or JavaScript or PHP function, then hit Enter.
  2. If you have an indent, continue to step 3. If not, create an indent with Tab or 4 spaces (whatever your religion is).
  3. Hit the Backspace key; notice it merely removes an indent each time instead of deleting the whole line and putting your cursor at the end of the previous line like awesome JetBrains software does. Realize how many unnecessary keystrokes you'll now have to deal with (and Ctrl+Shift+Up-End each line is still a lot).
  4. Continue to use VS Code because nobody can afford to buy another JetBrains license for your new job.

This should be standard logic in all editors; there's zero functional or stylistic reason to want to just delete indents on an empty line with Backspace (unless there's too many indents there which is rare, or your editor auto-indented wrong), and even if for some Pan-like reason you need to use that regressive space, you can just use Ctrl+Home to delete the line then indent where you want (or Shift+arrow, or just arrow if you're a weirdo).

Does this issue occur when all extensions are disabled?: Yes

rmunn commented 6 years ago

I like this feature idea, but one other thing to think about is the interaction with the editor.trimAutoWhitespace setting. If editor.trimAutoWhitespace is false, then I might want to delete some whitespace after hitting Enter, while still keeping the new line. And in those situations, reaching for the Backspace key would feel like the most natural way to do it.

So if this is implemented, I'd like to see a setting to turn it off for the rare cases when I might actually need to backspace over some auto-inserted whitespace (e.g., if I've turned editor.trimAutoWhitespace off for some reason).

mccreeker commented 6 years ago

Auto-adding whitespace should happen only after hitting Enter on an indented line, and only be added up to the beginning of the previous line or one indent more if it's inside a nesting (or maybe two more such as inside an HTML tag or PHP array so that the inner contents aren't on the same line as the following block segment), and I could see how it would be useful to just delete the empty whitespace on the line (instead of deleting the line), but this means two Backspaces to delete the line.

It's easy to see how Eclipse, JetBrains, and NetBeans editors handle Enter indentation and Backspace on empty or indent-only lines, though the JetBrains way has been the most useful and avoided the most keystrokes in my usage of all code editors I've used.

vasilev-alex commented 5 years ago

That is something that should be implemented natively in VS Code. But for now I found this extension really useful https://marketplace.visualstudio.com/items?itemName=jasonlhy.hungry-delete

Saves up hours a day :)

rmunn commented 5 years ago

If #71506 is implemented, that would probably solve this one as well.

waleedrana777 commented 2 years ago

+1

edgarwideman commented 1 year ago

Still looking for this solution. Any updates?

ryankhart commented 1 year ago

@edgarwideman Have you tried this extension yet? It worked almost as well as how the JetBrains IDEs do it for me. Just not well enough to justify closing this issue just yet, in my opinion. https://marketplace.visualstudio.com/items?itemName=jasonlhy.hungry-delete

edgarwideman commented 1 year ago

I did find it after dropping previous comment. Thanks anyway. 👍

starball5 commented 7 months ago

Related on Stack Overflow: Move cursor up after deleting a line in VSCode

If there were a context key that contained the text preceding the cursor in its current line, or even one containing the entire contents of the current line, you could write a keybinding that would do this using various editor commands in runCommands and with a when clause using the match operator.

ArturoDent commented 7 months ago

I posted a possible solution on SO: https://stackoverflow.com/a/78290422/836330

deleteEmptyLinesMoveCursorUp2

It is just a keybinding, no extension necessary.