11

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).

Sid110307
  • 497
  • 2
  • 8
  • 22
  • With your edit the easiest is just to use the `Go to Line/Column` command, default keybinding is Ctrl+G and then type the line number you want to go to. There may be extensions that do that too - but no less "work". I'll reopen with your edit. There is no built-in feature to do what you ask other than the `Go to line` command. – Mark Jan 03 '22 at 06:12
  • I use relative line numbering. Is there a way to go to line with relative numbers? For example, I am on line 69 and I want to go up 24 lines, Do I have to subtract and type 45 or is there an easier way (Something like ctrl+number and arrow key in emacs)? – Sid110307 Jan 03 '22 at 06:17
  • You edited to add `Cursor` to the title - do you want to move the cursor up 25 lines or move a line up 25 lines (since you referenced Alt+Arrow which moves the line)? – Mark Jan 03 '22 at 18:17
  • I want to move the cursor. – Sid110307 Jan 04 '22 at 08:14
  • I used @rioVB's answer and changed `editor.action.moveLinesUpAction` to `cursorUp`, and the same for down – Sid110307 Jan 04 '22 at 08:15
  • I just want to move the cursor n lines. Like how emacs has Ctrl+Number and then the key (If i press ctrl+6 and then the down arrow, I move the cursor down 6 times) – Sid110307 Jan 04 '22 at 08:15
  • In which case you should use the `cursorMove` command as seen at https://stackoverflow.com/a/48568520/836330 rather than repeating `cursorUp` 10 times. And no need for the macro extension then (since you are running just one command). – Mark Jan 04 '22 at 12:29
  • I don't want to move 10 times always. I want to move the amount I choose. Like how emacs has Ctrl+Number and then the key (If i press ctrl+4 and then the down arrow, I move the cursor down 4 times, or If I press ctrl+22 and then the up arrow, I move the cursor up 22 times) – Sid110307 Jan 04 '22 at 13:09
  • I understand - I was saying if you are going the route suggested in the answer below use `cursorMove` with its args rather than making a keybinding with 10 or whatever `cursorUp`'s and an unnecessary macro extension. – Mark Jan 04 '22 at 13:25
  • So how do I do it? – Sid110307 Jan 04 '22 at 17:43
  • Why do you give the key combo `Alt+Arrow` (moveLines) when you only want to jump the cursor to a new location (cursorMove) – rioV8 Jan 06 '22 at 12:31

3 Answers3

16

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.

Mark
  • 143,421
  • 24
  • 428
  • 436
0

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": [
rioV8
  • 24,506
  • 3
  • 32
  • 49
0

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

bejzik8
  • 11
  • 1