skip to Main Content

I want to jump x lines vertically when im in selection/highlight mode in VSCode.

That’s what i tried so far:

keybindings.json:

 {
        "key": "cmd+[Backquote]",
        "command": "runCommands",
        "args": {
            "commands": [
                {
                    "command": "cursorMove",
                    "args": {
                        "to": "up",
                        "by": "line",
                        "value": 10
                    }
                }
            ]
        },
        "when": "editorHasSelection"
    }

It works fine without selection:

    {
        "key": "cmd+[Backquote]",
        "command": "cursorMove",
        "args": {
            "to": "up",
            "by": "line",
            "value": 10
        },
        "when": "editorTextFocus"
    },

2

Answers


  1. Not exactly what you’re asking for, but it sounds to me kind of like you want the anchor selection commands. Before using your jump command, just set a selection anchor, and then once you’ve jumped to where you want the selection to end, use the command to select from the anchor to your cursor. Then you don’t even need to when-clause for selection context. You can just use a regular cursor-move keybinding for the jumping bit.

    Login or Signup to reply.
  2. If you are trying to select a range of lines from a current selection than this works for me:

    {
      "key": "cmd+[Backquote]",
      "command": "runCommands",
      "args": {
          "commands": [
              {
                  "command": "cursorMove",
                  "args": {
                      "to": "up",
                      "by": "line",
                      "value": 10,
                      "select": true     // use this argument
                  }
              }
          ]
      },
      "when": "editorHasSelection"
    },
    

    By the way, there is no need to use the runCommands command – it is for running multiple commands in sequence. This simpler version works:

    {
      "key": "cmd+[Backquote]",
      "command": "cursorMove",
      "args": {
          "to": "up",
          "by": "line",
          "value": 10,
          "select": true     // use this to select from current selection to cursor move point
      },
      "when": "editorHasSelection"
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search