Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code - How to jump by word with [Alt]+[Left/Right]

I've started using Visual Studio Code on MacOS.

Jumping with Alt+Left/Right is really annoying as it jumps by full identifier instead of just a word.

Examples:

  • ▼create_foo() Alt+Right create_foo▼()
  • ▼createFoo() Alt+Right createFoo▼()

I'd like e.g. Ctrl+Right to do the thing above and to modify the behaviour of Alt+Right so it jumps by word.

My desired behaviour:

  • ▼create_foo() Alt+Right create_▼foo()
  • ▼create_foo() Ctrl+Right create_foo▼()

Solution:

My final keybindings.jsonconfig with the added Shift (select) options:

[
    {
        "key": "alt+left",
        "command": "cursorWordPartLeft",
        "when": "editorTextFocus",
    },
    {
        "key": "alt+right",
        "command": "cursorWordPartRight",
        "when": "editorTextFocus",
    },
    {
        "key": "shift+alt+left",
        "command": "cursorWordPartLeftSelect",
        "when": "editorTextFocus"
    },
    {
        "key": "shift+alt+right",
        "command": "cursorWordPartRightSelect",
        "when": "editorTextFocus"
    },
    {
        "key": "ctrl+left",
        "command": "cursorWordStartLeft",
        "when": "editorTextFocus"
    }, 
    {
        "key": "ctrl+right",
        "command": "cursorWordEndRight",
        "when": "editorTextFocus"
    },
    {
        "key": "shift+ctrl+left",
        "command": "cursorWordStartLeftSelect",
        "when": "editorTextFocus"
    },
    {
        "key": "shift+ctrl+right",
        "command": "cursorWordEndRightSelect",
        "when": "editorTextFocus"
    },
]
like image 787
Mice Pápai Avatar asked Feb 18 '19 11:02

Mice Pápai


People also ask

How to quickly jump between files in Visual Studio Code?

However, when you are working on a task, you will find yourself quickly jumping between the same set of files. VS Code provides two powerful commands to navigate in and across files with easy-to-use key bindings. Hold Ctrl and press Tab to view a list of all files open in an editor group.

Does Visual Studio Code jump by full identifier instead of word?

I've started using Visual Studio Code on MacOS. Jumping with Alt + Left/Right is really annoying as it jumps by full identifier instead of just a word. I'd like e.g. Ctrl + Right to do the thing above and to modify the behaviour of Alt + Right so it jumps by word. My final keybindings.json config with the added Shift (select) options:

How do you jump a word in terminal?

My fingers are programmed to use ctrl+right arrow to jump a word forward, ctrl+left arrow to jump a word back, in Terminal. I have disabled Mission Control.

What is Visual Studio Code tips and tricks?

"Tips and Tricks" lets you jump right in and learn how to be productive with Visual Studio Code. You'll become familiar with its powerful editing, code intelligence, and source code control features and learn useful keyboard shortcuts.


1 Answers

You are looking for

cursorWordPartRight

which is bound to Shift-Alt-Q.

Alt-Right is bound to a "Go Forward" command, you could delete that binding and use it for the cursorWordPartRight command.

{
    "key": "alt+right",
    "command": "cursorWordPartRight",
    "when": "editorTextFocus",
  },
  {
    "key": "alt+left",
    "command": "cursorWordPartLeft",
    "when": "editorTextFocus",
  }

It may require that each language parser support it though. It does work in JavaScript.

cursorWordPartLeft (command exists but is unbound by default).

There are also these other unbound relevant commands:

cursorWordPartRightSelect
cursorWordPartLeftSelect
cursorWordPartStartLeft
cursorWordPartStartLeftSelect
like image 102
Mark Avatar answered Sep 20 '22 19:09

Mark