In VScode, is there a way to go next line per two or three with shortcut?

Viewed 2159

I usually use ctrl + n/p to go to next/previous line in VSCode. But it sometimes makes me feel dull because it has the cursor go just one line when I want to browse the file casually.Then, is there way to have the cursor go per a few lines or other more quick way to browse file(like go to next class or method definition)?

4 Answers


Jumping Lines in V.S. Code




V.S. Code Keyboard Shortcuts


        V.S. Code offers its users the ability to customize Keyboard Shortcuts using navigational type commands that move the cursor, via the "keybindings.json" configuration file. When the "keybindings.json" file is configured properly you are able to use Keyboard Shortcuts to jump up n-lines, jump down n-lines, jump left n-chars, or to jump right n-chars.

  • NOTE: "n can equal any number".


Getting Started


        To navigate the cursor in the fashoin that this topic covers, you will need to configure a few customized V.S. Code Keybindings (aka Keyboard Shortcuts). If this is not somthing that you have done before you don't need to worry. Binding a shortcut to a unique combonation of keys is actually quite simple, and it can be whimsical as well. It certainly will improve your V.S. Code experiance.

To get started creating your "line-jumping" Keyboard Shortcuts follow the instructions below. If you need any extra help during the keybinding creation process you can use the official V.S. Code, community maintained, documentation as a guide. I have posted the link below:

V.S. Code: Keyboard Shortcuts



  1. – Use the F1 Key to open your "Quick Input Drop-Down Menu"

  2. – Type "Keyboard Shortcut" into the "Quick Input Menu".

  3. – Select "Open Keyboard Shortcuts (JSON)"

Note: There will be two "Keyboard Shortcut" options that you will be able to choose from. One of the options will read default, and one WILL NOT read default. Make sure to select the one that DOES NOT read default. If you are unfamiliar with keybindings, and have never created one before then the file should be totally empty.


Once inside of the keybindings.json file, add the following "JSON" block to the file

// "keybindings.json"

{
  {
    "key": "ctrl+1",
    "when": "editorTextFocus",
    "command": "cursorMove",
    "args": {
      "by": "line",
      "to": "down",
      "value": 1
    }
  },

  {
    "key": "ctrl+2",
    "when": "editorTextFocus",
    "command": "cursorMove",
    "args": {
      "by": "line",
      "to": "down",
      "value": 5
    }
  },

  {
    "key": "ctrl+3",
    "when": "editorTextFocus",
    "command": "cursorMove",
    "args": {
      "by": "line",
      "to": "down",
      "value": 10
    }
  },

  {
    "key": "ctrl+shift+1",
    "when": "editorTextFocus",
    "command": "cursorMove",
    "args": {
      "by": "line",
      "to": "up",
      "value": 1
    }
  },

  {
    "key": "ctrl+shift+2",
    "when": "editorTextFocus",
    "command": "cursorMove",
    "args": {
      "by": "line",
      "to": "up",
      "value": 5
    }
  },

  {
    "key": "ctrl+shift+3",
    "when": "editorTextFocus",
    "command": "cursorMove",
    "args": {
      "by": "line",
      "to": "up",
      "value": 10
    }
  },
}

"The above is only for testing purposes, as the keybindings are simple, and override default VSCode keybindings. You will have to decide which keybindings work best for you, however; if you add the above to your "keybindings.json" file you will get the following Keyboard Shortcuts"

  1. Jump Down a Line      CTRL+1

  2. Jump Down 5 Lines    CTRL+2

  3. Jump Down 10 Lines  CTRL+3

  4. Jump Up a Line      CTRL+SHIFT+1

  5. Jump Up 5 Lines    CTRL+SHIFT+2

  6. Jump Up 10 Lines  CTRL+SHIFT+3



For More Help:


For further assistance Visit the VSCode Commands Page to a list of all commands, or to read specifically about the cursorMove command @:
...or to read about keybindings visit keybindings page that is included the opensource community maintained VSCode documentation collection @:


From the extension Select By you can use the moveby.calculation command.

keybindings.json

{
    "key": "ctrl+i ctrl+5",  // or any other key binding
    "when": "editorTextFocus",
    "command": "moveby.calculation",
    "args": {
      "lineNrEx": "selection.start.line + 5",
      "charNrEx": "selection.start.character"
    }
  }

Many thanks to @j D3V for his answer. in new version of vsCode the right syntax for this combination is: forExample : ctrl+numpad1 this is edited json file that @j D3V mentioned in his answer :

// Place your key bindings in this file to override the defaults
[
  {
    "key": "ctrl+numpad1",
    "when": "editorTextFocus",
    "command": "cursorMove",
    "args": {
      "by": "line",
      "to": "down",
      "value": 1
    }
  }
  ,

  {
    "key": "ctrl+numpad2",
    "when": "editorTextFocus",
    "command": "cursorMove",
    "args": {
      "by": "line",
      "to": "down",
      "value": 5
    }
  },

  {
    "key": "ctrl+numpad3",
    "when": "editorTextFocus",
    "command": "cursorMove",
    "args": {
      "by": "line",
      "to": "down",
      "value": 10
    }
  },

  {
    "key": "ctrl+shift+numpad1",
    "when": "editorTextFocus",
    "command": "cursorMove",
    "args": {
      "by": "line",
      "to": "up",
      "value": 1
    }
  },

  {
    "key": "ctrl+shift+numpad2",
    "when": "editorTextFocus",
    "command": "cursorMove",
    "args": {
      "by": "line",
      "to": "up",
      "value": 5
    }
  },

  {
    "key": "ctrl+shift+numpad3",
    "when": "editorTextFocus",
    "command": "cursorMove",
    "args": {
      "by": "line",
      "to": "up",
      "value": 10
    }
  },
]

As far as I know, there is no shortcut at the moment to skip multiple lines without extensions. However, ctrl + shift + o (by default) or prefixing your search query (ctrl + p by default) with an @ can be used to navigate through symbols in a file, which might be what you were looking for.

enter image description here

Related