Vscode: New command, "Select to Bracket", that will select the text between ...

Created on 10 Feb 2018  路  12Comments  路  Source: microsoft/vscode

  • VSCode Version: 1.21.0-ins
  • OS Version: win7x64

https://code.visualstudio.com/updates/v1_20#_select-text-while-jumping-between-brackets
tells us:

There is a new command, Select to Bracket, that will select the text _between two matching brackets_ (as opposed to the already existing command, Go to Bracket, which only moves the cursor to the matching bracket).

I'm not an expert in English, but I think "between two matching brackets" means, that brackets (parenthesis, etc.) should be _excluded_ from this selection...

select the text between

.. shouldn't they?

editor-bracket-matching feature-request verification-needed verified

Most helpful comment

We could add an argument to the command implementation.

It would be definable in keybindings.json like e.g.:

    {
        "key": "shift+cmd+\\",
        "command": "editor.action.selectToBracket",
        "args": { "selectBrackets": false }
    }

Those would be available in the last argument (not used now) for the run method:

public abstract run(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void | TPromise<void>;

https://github.com/Microsoft/vscode/blob/1633d0959a33c1ba0169618280a0edb30d1ddcc3/src/vs/editor/contrib/bracketMatching/bracketMatching.ts#L61

All 12 comments

I don't know what would be best, to select the brackets or not...

This came in as PR #39066 from @afonsobspinto

Hey. That's a great question. We faced the same one.
We ended up opting to select the brackets too since it was @chrisdavies's preference in the PR #28163

I vote for selecting the brackets as well. I'm often trying to yank code, which generally includes the brackets.

I should try to add support for multicursors soon, so let me know if you want me to change the behavior too.

@alexandrudima

how about to make an option?
1) with brackets
2) without brackets

We could add an argument to the command implementation.

It would be definable in keybindings.json like e.g.:

    {
        "key": "shift+cmd+\\",
        "command": "editor.action.selectToBracket",
        "args": { "selectBrackets": false }
    }

Those would be available in the last argument (not used now) for the run method:

public abstract run(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void | TPromise<void>;

https://github.com/Microsoft/vscode/blob/1633d0959a33c1ba0169618280a0edb30d1ddcc3/src/vs/editor/contrib/bracketMatching/bracketMatching.ts#L61

Is it possible to select without brackets now?
I looking for solution for selection without brackets because it's really useful.

Example - CSS rules sorting:

Step 1 - Select all without brackets
Step 2 - Run command - Sort lines Asc.

Above scenario is impossible right now :(

Ps. label smart-select should be added to this ticket i think :)

Let's say that there is a command called selectBracket.
Then selectBracket ( select the text between brackets does not include brackets themself.
selectBracket ) select the text between brackets include brackets themself.

You might be interested in Shrink/Expand Selection

@alexandrudima @afonsobspinto Do you have the opportunity to support this?

I want the behavior of selectToBracket to continue to expand(editor.action.smartSelect.grow) like Smart selection.

There is now a new argument to the command, which can be used via keybindings.json, e.g.:

{
    "key": "shift+cmd+\\",
    "command": "editor.action.selectToBracket",
    "args": { "selectBrackets": false }
}

Does anyone know - is there a shortcut key for editor.action.selectToBracket ? When I search through Keyboard Shortcuts it is not listed.

From what i know they didn't add this but it's not a problem because you can make your own shortcut:

{
    "key": "ctrl+shift+'",
    "command": "editor.action.selectToBracket",
    "args": {
        "selectBrackets": false
    }
}

From what i know they didn't add this but it's not a problem because you can make your own shortcut:

{
    "key": "ctrl+shift+'",
    "command": "editor.action.selectToBracket",
    "args": {
        "selectBrackets": false
    }
}

Thanks @kanlukasz ! If anyone reading this wants to know where you place this text ->
press ctrl+shift+p and type Preferences: Open Keyboard Shortcuts, select the Open Keyboard Shortcuts (JSON) icon top right and add it in there.
image
https://code.visualstudio.com/docs/getstarted/keybindings#_advanced-customization

Was this page helpful?
0 / 5 - 0 ratings

Related issues

v-pavanp picture v-pavanp  路  3Comments

vsccarl picture vsccarl  路  3Comments

shanalikhan picture shanalikhan  路  3Comments

philipgiuliani picture philipgiuliani  路  3Comments

villiv picture villiv  路  3Comments