Steve Turner
Steve Turner

Reputation: 51

Can VSCode start a selection that will automatically extend with cursor movement?

I'm evaluating VSCode as a replacement for Atom (which replaced SlickEdit), but I can't determine if it will support the selection behavior I was able to achieve with Atom and Slick. I have my cursor movement keys redefined, which is generally incompatible with holding down "shift" and extending the selection via standard cursor movement keys. Does VSCode support the notion of starting (or "anchoring") a selection with a key-mapping of my choice (say, Ctrl-M), then allowing the selection to move and extend as I navigate around with my other (redefined) cursor movement keys?

Upvotes: 3

Views: 373

Answers (2)

kevincasey
kevincasey

Reputation: 250

Solution for version 1.96.0.

After you set the selection anchor you can use a when clause in your keyboard rules to do alternative cursor movement commands that select as they move the cursor.

Every cursor movement command that you use may not have a corresponding selecting command. Here is a sample of the ones that I find useful:

cursorLineStartSelect
cursorLineEndSelect
cursorLeftSelect
cursorRightSelect
cursorUpSelect
cursorDownSelect
cursorTopSelect
cursorBottomSelect

You can see many more in the default key bindings.

Example

The default rule for cursorRight has an accompanying rule for cursorRightSelect.

{ "key": "ctrl+f",                "command": "cursorRight",
                                     "when": "textInputFocus" },
{ "key": "shift+right",           "command": "cursorRightSelect",
                                     "when": "textInputFocus" },

If you want the selection to happen automatically when an anchor is set you can add this new rule:

{ "key": "ctrl+f",
  "command": "cursorRightSelect",
  "when": "textInputFocus && selectionAnchorSet" }

That way you can continue using the same key bindings that you like for cursor movement. If an anchor is set you get movement and selection. If an anchor is not set you only get movement.

Note: With customized keybindings you have to make sure the movement only rules include !selectionAnchorSet in a when clause or make sure the movement only rules is after the corresponding movement with selection rule. This is because it uses the first matching rule that it finds when traversing the rules from top to bottom.

Disadvantage

This solution requires a significant amount of work to set up all the rules for all of the cursor movement commands that you use and may not work for more exotic commands. It would be nice if there was a way to enable the selecting behavior for all cursor movement commands without writing rules for each of them.

Upvotes: 0

Mark
Mark

Reputation: 181238

A partial solution is in the Insiders' Build and so maybe v1.46.

You can now anchor a selection start point and then later with a keybinding select everything between the cursor and that anchor point. The commands are:

Set Selection Anchor Ctrl+k Ctrl+b

Select From Anchor to Cursor Ctrl+k Ctrl+k

Go to Selection Anchor

See Anchor selections testing

Not exactly what you wanted but a big step in the right direction.

Upvotes: 3

Related Questions