3

I've found how to customize a keybinding for jumping to the closest empty line here.

But I wonder if I can, in the same way, set a keybinding for selection of paragraph or to the next empty line. I'd like it to select from where the cursor is to the next (with Ctrl + Shift + DownArrow) or previous empty line (with Ctrl + Shift + UpArrow)

More generally, I don't know how to search for existing, valid "command" to configure my own keybindings in the keybindings.json file.

4
  • Hi, do you want to select from where the cursor is to the next empty line or back to previous empty line, then select until next empty line? I assume the 2nd since you wrote "paragraph" but just making sure. Bindable commands are findable e.g. if you open keyboard shortcut settings in VSCode, you can also search them.
    – Destroy666
    May 12, 2023 at 13:08
  • @Destroy666 No I mean the first one. I'd probably used the jump to next empty line shortcut I've set up to place my cursor on a empty line if I want to select from there May 12, 2023 at 15:59
  • Now I'm very confused with your 2nd sentence above. Please edit the initial post with 2 screens - example of where the cursor is initially and what exactly needs to be selected after pressing the hotkey combination.
    – Destroy666
    May 12, 2023 at 19:12
  • @Destroy666 I'd like it to select from where the cursor is to the next (with Ctrl+Shift+DownArrow) or previous empty line (with Ctrl+Shift+UpArrow). May 12, 2023 at 22:06

1 Answer 1

4

You need to bind cursorMove command with proper args. To bind:

  • selecting from cursor to next blank line with Ctrl + Shift + Down
  • selecting from cursor to previous blank line with Ctrl + Shift + Up

you can use:

    {
        "key": "ctrl+shift+down",
        "command": "cursorMove",
        "when": "editorTextFocus",
        "args": {
            "to": "nextBlankLine",
            "select": true
        }
    },
    {
        "key": "ctrl+shift+up",
        "command": "cursorMove",
        "when": "editorTextFocus",
        "args": {
            "to": "prevBlankLine",
            "select": true
        }
    }

Add it to keybindings.json by e.g. executing Command Palette (Shift + Ctrl + P) -> Preferences: Open Keyboard Shortcuts (JSON) command.

As a bonus, to bind one shortcut to select an entire paragraph, as the title of the question suggests, a runCommands macro can be used:

{
    "key": "ctrl+shift+a",
    "command": "runCommands",
    "when": "editorTextFocus",
    "args": {
        "commands": [
            {
                "command": "cursorMove",
                "args": {
                    "to": "prevBlankLine"
                }
            },
            {
                "command": "cursorMove",
                "args": {
                    "to": "nextBlankLine",
                    "select": true
                }
            }
        ]
    }
}

Check cursorMove documentation for more info.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .