Sid110307
Sid110307

Reputation: 568

Move Cursor Up or Down Multiple Lines at once in VS Code

Note: I have searched in Google and other SO posts, but none of them have helped me.

I know that we can move up or down with Alt+Arrow. Is there a way to move, let's say 25 lines up, at once? I don't want to press Alt+ 25 times.

Is there a plugin or a built-in feature to do this?

The reason I'm asking is that it's easier to move multiple lines at once due to the relative line numbers feature in VS Code.

I don't want to specify each number in keybindings.json (As seen here).

Upvotes: 17

Views: 14076

Answers (3)

basic
basic

Reputation: 11

I do not think there is an option to achieve what you want with VS Code only but there is an extremely powerful Vim plugin which is based on Vim terminal text editor. You should check it out, you can do anything you imagine with it but it takes some time to get used to it.

https://marketplace.visualstudio.com/items?itemName=vscodevim.vim

Upvotes: 0

Mark
Mark

Reputation: 180641

To make it easier to navigate the cursor in blocks of lines you could set a keybinding to jump 10 lines up or down at once (in your keybindings.json):

{
    "key": "ctrl+up",         // whatever keybinding you want
    "command": "cursorMove",
    "args": {
        "to": "up",
        "by": "line",
        "value": 10         // change this if you want
    },
    "when": "editorTextFocus"
},
{
    "key": "ctrl+down",        // whatever keybinding you want
    "command": "cursorMove",
    "args": {
        "to": "down",
        "by": "line",
        "value": 10         // change
    },
    "when": "editorTextFocus"
}

As noted in the comments, this comes from https://stackoverflow.com/a/48568520/836330 so upvote that.

Upvotes: 28

rioV8
rioV8

Reputation: 28623

You can use multi-command

Like in Photoshop when you move something Arrow moves 1 pixel, Shift+Arrow moves 20 pixels.

The Arrow key has no modifier combo unused so we have to choose a different key.

New keybindings to move up or down 10 lines

{
  "key": "alt+numpad8",  // or any other key combo
  "command": "extension.multiCommand.execute",
  "args": { 
    "sequence": [
      "editor.action.moveLinesUpAction",
      "editor.action.moveLinesUpAction",
      "editor.action.moveLinesUpAction",
      "editor.action.moveLinesUpAction",
      "editor.action.moveLinesUpAction",
      "editor.action.moveLinesUpAction",
      "editor.action.moveLinesUpAction",
      "editor.action.moveLinesUpAction",
      "editor.action.moveLinesUpAction",
      "editor.action.moveLinesUpAction"
    ]
  },
  "when": "editorTextFocus && !editorReadonly"
},
{
  "key": "alt+numpad2",
  "command": "extension.multiCommand.execute",
  "args": { 
    "sequence": [
      "editor.action.moveLinesDownAction",
      "editor.action.moveLinesDownAction",
      "editor.action.moveLinesDownAction",
      "editor.action.moveLinesDownAction",
      "editor.action.moveLinesDownAction",
      "editor.action.moveLinesDownAction",
      "editor.action.moveLinesDownAction",
      "editor.action.moveLinesDownAction",
      "editor.action.moveLinesDownAction",
      "editor.action.moveLinesDownAction"
    ]
  },
  "when": "editorTextFocus && !editorReadonly"
}

Maybe you have to add a little delay

  "args": { 
    "interval": 50,
    "sequence": [

Upvotes: 0

Related Questions