microsoft / vscode

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

Remove current cursor (multi-cursor) using the keyboard #211724

Open musjj opened 2 months ago

musjj commented 2 months ago

Currently, the only way to remove a cursor in a multi-cursor context is to manually Alt+Click using the mouse.

Combined with editor.action.focusNextCursor and editor.action.focusPreviousCursor, a command to remove the current cursor will allow the user to easily remove any arbitrary cursor with just using the keyboard.

VSCodeTriageBot commented 4 weeks ago

This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 20 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

spartanatreyu commented 4 weeks ago

If you're using multi-cursor with Find Next Occurrence (Ctrl/Cmd + d) then you have this with slightly confusingly named Move Last Selection To Next Find Match (Ctrl/Cmd + k, Ctrl/Cmd + d) and Cursor Undo (Ctrl/Cmd + u).

If you press Ctrl/Cmd + d one too many times, you can press Ctrl/Cmd + u to put your multiple selection back to how it was before you pressed Ctrl/Cmd + d.

If you're pressing Ctrl/Cmd + d but want to undo the selection you just made, make vscode pretend that piece of code doesn't exist and then continue making additional selections, you can press Ctrl/Cmd + k then press Ctrl/Cmd + d.

For example, selecting all chapters except chapter 4:

"course1": {
    "overview": "/online-course",
    "chapter1": "/online-course/chapter-1",    // <- select "chapter"
    "chapter2": "/online-course/chapter-2",    // <- select "chapter"
    "chapter3": "/online-course/chapter-3",    // <- select "chapter"
    "chapter4": "/online-course/chapter-4",    // <- NOT THIS ONE
    "chapter5": "/online-course/chapter-5",    // <- select "chapter"
    "chapter6": "/online-course/chapter-6"     // <- select "chapter"
}
  1. Highlight first occurrence of chapter-
  2. Press Ctrl/Cmd + d to add chapter 2
  3. Press Ctrl/Cmd + d to add chapter 3
  4. Press Ctrl/Cmd + d to add temporarily add chapter 4
  5. Press Ctrl/Cmd + k then Ctrl/Cmd + d to unselect chapter 4 and select chapter 5
  6. Press Ctrl/Cmd + d to add chapter 6

If you're not using Ctrl/Cmd + d to select items but instead using something like Select All Occurrences Of Next Match (Ctrl/Cmd + Shift + l) and wanting to deselect specific selections without using a mouse because there's too many matches to Ctrl/Cmd + d them all then this makes more sense.

In terms of the use-case for adding this feature (trying to multi-select many things except for specific cases as determined by the user), the use-case is shared by the issue here: https://github.com/microsoft/vscode/issues/212562