Is there in vscode an option to: Select everything between matching brackets

前端 未结 7 1239
孤街浪徒
孤街浪徒 2020-12-08 13:48

Is there in vscode a shortcut available which selects all code between matching brackets e.g. in atom this shotcut is ctrl+alt+m

相关标签:
7条回答
  • 2020-12-08 13:58

    In MacOS: it's shift + control + right, you hit right a few time to expand the smartSelect.

    • To find your own settings related to smartSelect, go to Keyboard Shortcuts or use command + k command + s.
    • You can check VSCode Keyboard Shortcuts Reference by typing command + k command + r. It will lead you to this page.
    0 讨论(0)
  • 2020-12-08 14:09

    editor.action.smartSelect.expand, assigned to ctrl+shift+right will expand your current selection, so inside a string, will expand to the current word, and to the whole string when pressed again. I think this is the proper shortcut to learn because it can also expand beyond the string to select ever more wrappers, which is a pretty neat thing to be able to do.

    As of v1.44, there is no keyboard shortcut assigned to editor.action.smartSelect.grow anymore, as mentioned in the current accepted answer by Wosi.

    0 讨论(0)
  • 2020-12-08 14:11

    I am using this extension, called Quick and Simple Text Selection - yes, that's the name :)

    If you don't want to use an extension, this is the best I come up with so far: go to edit keyboard shortcuts and from there open your keybindings.json file and add the following lines

    {
        "key": "ctrl+'",
        "command": "editor.action.smartSelect.grow",
        "when": "editorTextFocus"
    }
    
    0 讨论(0)
  • 2020-12-08 14:12

    I suggest to remap those keys to another key, this key combination is popular, sometimes it doesn't work because of the conflict with other apps.

    Open the key binding setting, type the smartselect to find this setting, grow is expand the selection from the cursor current position to the nearest bracket, press multiple times if you want to expand or shrink to the next bracket.

    0 讨论(0)
  • 2020-12-08 14:20

    Place the cursor inside the bracket (not directly next to a bracket) and execute editor.action.smartSelect.grow until everything inside the bracket is selected. The default shortcut is Shift+Alt+Right.

    You can shrink the selection with editor.action.smartSelect.shrink which has the default shortcut Shift+Alt+Left.

    0 讨论(0)
  • 2020-12-08 14:20

    I still think the expand region extension is the way to go on this. But vscode 1.20 did add the "Select to Bracket" command (see command palette). It has no default keybinding but the command is

    editor.action.selectToBracket
    

    so you can assign your own binding. But it is not as handy as the extension. The smartSelect options mentioned above give me unexpected/unwanted results.

    ---------- Update ---------------

    editor.action.smartSelect.expand command was added at some point after the answers here.

    Bound to Shift+Alt+RightArrow. Will progressively expand the selection including to within and not including the brackets, parentheses if you wish. You will need to keep triggering the RightArrow to get to where you want. Will not select only within the brackets if you start right next to a bracket - start anywhere else and it will.

    0 讨论(0)
提交回复
热议问题