visual-studio-codekeyboard-shortcutskey-bindingsvscode-keybinding

Visual Studio Key Bindings - Have the same Key Binding do different Tasks with each Subsequent Press


In VS Code, the shortcut "Ctrl + A" selects everything in the document. I'm used to a more progressive selection system like Microsoft OneNote where Ctrl + A behaves the following way:

  1. Selects the current paragraph (First Press Ctrl + A)
  2. Selects all indented subparagraphs if applicable (Second Press)
  3. Selects the current cell (Third Press)
  4. Selects the whole document (Fourth Press)

In a perfect world, I'd like some method so I can rebind Ctrl + A in the .json file to do the following from just a default cursor position:

  1. Select the current word
  2. Select the current line
  3. Select the current fold/indent section (may not be possible)
  4. Select the whole document

I don't know if there is a command for selecting the current word. I do know there is a command for selecting the current line (Ctrl + L, expandLineSelection). I think the way I would go about progressively changing what the command does is by modifying the when section for each level of the command, but I don't even know where to start with that


Solution

  • starball's suggestion is close enough to what I wanted to achieve so I'm going to use it. To reiterate; the Command is "editor.action.smartSelect.expand" and I just edit the Json file to disable the original command and use the new command in conjunction with the default shortcut (Alt + Shift + RightArrow).

    // Place your key bindings in this file to override the defaults
    [
        {
            "key": "ctrl+a",
            "command": "editor.action.smartSelect.expand",
            "when": "textInputFocus"
          },
        {
            "key": "ctrl+a",
            "command": "-editor.action.selectAll"
        }
    ]