Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple actions on one keyboard shortcut in vscode

Is it possible to have multiple actions assigned to one keyboard shortcut in visual studio code?

For example: Move cursor up x 3 set to "ctrl + w"

Thanks in advance.

like image 753
M. Robertson Avatar asked May 03 '16 16:05

M. Robertson


People also ask

What is Ctrl K in VS Code?

To launch the Define Keybinding widget, press Ctrl+K Ctrl+K. The widget listens for key presses and renders the serialized JSON representation in the text box and below it, the keys that VS Code has detected under your current keyboard layout.

How do you edit multiple things at once in VS Code?

Use Ctrl + D to use multi word edit of same words in Windows and Linux.

What is Ctrl Shift P in VS Code?

You can define a keyboard shortcut for any task. From the Command Palette (Ctrl+Shift+P), select Preferences: Open Keyboard Shortcuts File, bind the desired shortcut to the workbench.

What is Ctrl D in VS Code?

Ctrl + D in Visual Studios (Any Edition) to copy the line down. The equivalent Keyboard Shortcut in VS Code IDE to copy line down : Shift + Alt + ↓


2 Answers

It's possible with extensions like Commands

settings.json

"commands.commands": {     "down3": {         "sequence": [             "cursorDown",             "cursorDown",             "cursorDown",         ],     }, }, 

keybindings.json

{     "key": "ctrl+w",     "command": "down3", }, 

Or with just keybindings.json

{     "key": "ctrl+w",     "command": "commands.run",     "args": [         "cursorDown",         "cursorDown",         "cursorDown"     ] }, 

Feature request to support Macro like keybindings #871.


Although, for this particular example it's better to use the built-in command (to avoid any jumpiness):

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

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

like image 128
Alex Avatar answered Oct 02 '22 06:10

Alex


I use the macros extension (https://marketplace.visualstudio.com/items?itemName=geddski.macros):

in settings.json:

"macros": {     "showGit": ["workbench.view.scm", "git-graph.view"] } 

then in keybindings.json:

{     "key": "ctrl+shift+g",     "command": "showGit" } 
like image 21
Nitsan Baleli Avatar answered Oct 02 '22 05:10

Nitsan Baleli