39

Im playing around with the idea of using Microsoft VS code as a text editor. Currently I am a sublime user and I have it configured to be able to jump 10 lines vertically (up or down) when I use the key combinations OPT key + Up or down. I would like this same functionality on VS Code but cannot find a way to duplicate it there. Can someone please outline how I can go about solving this. Thanks.

Additional information: Operating System: OSX 10.13 (High Sierra)

Martin S
  • 814
  • 2
  • 11
  • 24
user2737876
  • 1,038
  • 2
  • 12
  • 20
  • https://stackoverflow.com/questions/37009184/multiple-actions-on-one-keyboard-shortcut-in-vscode/43950204#43950204 – Alex Oct 31 '17 at 17:32

4 Answers4

114

Put this into keybindings.json

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

cursorMove - Move cursor to a logical position in the view

args:

to: A mandatory logical position value providing where to move the cursor.

'left', 'right', 'up', 'down', 'prevBlankLine', 'nextBlankLine',
'wrappedLineStart', 'wrappedLineEnd', 'wrappedLineColumnCenter'
'wrappedLineFirstNonWhitespaceCharacter', 'wrappedLineLastNonWhitespaceCharacter'
'viewPortTop', 'viewPortCenter', 'viewPortBottom', 'viewPortIfOutside'

by: Unit to move. Default is computed based on 'to' value.

'line', 'wrappedLine', 'character', 'halfLine'

value: Number of units to move. Default is '1'

select: If 'true' makes the selection. Default is 'false'.

https://code.visualstudio.com/api/references/commands

Wenfang Du
  • 8,804
  • 9
  • 59
  • 90
Alex
  • 59,571
  • 22
  • 137
  • 126
  • where to place these codes.. can't apply in the settings.json – DhineshYes Apr 19 '19 at 06:44
  • 1
    @DhineshYes go to keyborad shortcut settings and click the {} on the top right to add – we22gz May 17 '19 at 02:26
  • Thank you for the answer. I am a MacUser, and I use "alt+up" and "alt+down" instead because "Ctrl+Up" shortcut is taken by OS. – Hui Zheng May 25 '21 at 21:48
  • For MacOS users, go to MacOS System Preferences -> Keyboard -> Shortcuts -> Mission Control and deactivate the default OS behavior. Then this shortcut works for you as well (if you do not have any interest in Mission Control like me). I did not want to use the alt instead of ctrl key binding as mentioned earlier, because this is already used for moving the current line (e.g. alt+up moves the current line up). – Robin Wieruch Jul 18 '23 at 08:09
4

Just install line-jumper by alekseychaikovsky

It does everything as Sublime did for BOTH jumping lines AND selecting them as you jump.

The "cursorMove" solution in keybindings.json does NOT select lines and also is a tedious task. Just install extension "line-jumper" and you are done.

Acker Apple
  • 395
  • 2
  • 3
  • Note this will kill vscode's default alt+shift+down to duplicate line :'( – jpmc Jan 24 '21 at 05:25
  • First, command shift D is duplicate line. Second you goto key bindings setting and set anything to what you want – Acker Apple Jan 25 '21 at 14:14
  • Ah cool i didn't realise you could change the plugin shortcuts, my mistake. Cmd+shift+D isn't duplicate line in the vscode world tho – jpmc Jan 25 '21 at 15:43
  • The built-in command `cursorMove` does select lines if you wish - it is one of its options, as noted in the accepted answer. – Mark Feb 02 '21 at 17:29
  • Can be very slow over remote. Accepted answer is blazing fast and can easily add selection capability – chris Jan 16 '22 at 14:29
3

For QMK users

You can get the ability to move 10 lines anywhere (not just vsCode) by programming macros on your keyboard.

Do take a look at the documentation about macros as I'm certainly forgetting details, but a minimal example looks like this:

// keymap.c

// ...lots of #includes and #defines

enum custom_keycodes {
  TENDOWN,
  TENUP,
};

// use TENDOWN and TENUP in your keymaps

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  switch(keycode) {
    case TENUP:
      if (record->event.pressed) {
        SEND_STRING(
          SS_TAP(X_UP)
          SS_TAP(X_UP)
          SS_TAP(X_UP)
          SS_TAP(X_UP)
          SS_TAP(X_UP)
          SS_TAP(X_UP)
          SS_TAP(X_UP)
          SS_TAP(X_UP)
          SS_TAP(X_UP)
          SS_TAP(X_UP)
        );
      }
      break;
    case TENDOWN:
      if (record->event.pressed) {
        SEND_STRING(
          SS_TAP(X_DOWN)
          SS_TAP(X_DOWN)
          SS_TAP(X_DOWN)
          SS_TAP(X_DOWN)
          SS_TAP(X_DOWN)
          SS_TAP(X_DOWN)
          SS_TAP(X_DOWN)
          SS_TAP(X_DOWN)
          SS_TAP(X_DOWN)
          SS_TAP(X_DOWN)
        );
      }
      break;
  }
  return true;
}
Félix Paradis
  • 5,165
  • 6
  • 40
  • 49
0

For jumping across multiple lines, an alternative is to use an extension like Jump, it supports:

  • Jump to the Start of a word
  • Jump to the End of a word
  • Select to the Start of a word
  • Select to the End of a word

Demo of jumping to the end of a word:

Jump to the End of a word

Wenfang Du
  • 8,804
  • 9
  • 59
  • 90