Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable keychords of 3 or more steps #6966

Closed
zpdDG4gta8XKpMCd opened this issue May 27, 2016 · 23 comments · Fixed by #175253
Closed

enable keychords of 3 or more steps #6966

zpdDG4gta8XKpMCd opened this issue May 27, 2016 · 23 comments · Fixed by #175253
Assignees
Labels
feature-request Request for new features or functionality insiders-released Patch has been released in VS Code Insiders keybindings VS Code keybinding issues verification-needed Verification of issue is requested verified Verification succeeded
Milestone

Comments

@zpdDG4gta8XKpMCd
Copy link

zpdDG4gta8XKpMCd commented May 27, 2016

  • VSCode Version: 1.1.1
  • OS Version: Windows7, x64

Steps to Reproduce:

  1. Create a key-chord of 3 steps: "ctrl+k ctrl+c d" and bind it to a command
  2. Try the new key-chord
  3. Observe no action

Expected: 3 steps key-chords should work.

@alexdima alexdima added feature-request Request for new features or functionality keybindings VS Code keybinding issues labels Aug 9, 2016
@alexdima alexdima added this to the Backlog milestone Aug 9, 2016
@siegebell
Copy link

siegebell commented Oct 29, 2016

I'm writing an extension that provides an alternative to the ubiquitous use of emacs for a particular language. Some potential users are demanding that their crazy many-chorded keybindings be supported before moving to vscode...

@siegebell
Copy link

I can almost write an extension to provide this behavior...

Say I want to map ctrl+c ctrl+a ctrl+b to some.command. I can add these keybindings:

{"key": "ctrl+c ctrl+a", "command": "chords.c.a" },
{"key": "ctrl+b", "command": "some.command", "when": "chord.c.a"}

Where command chords.c.a calls vscode.commands.executeCommand("setContext","chord.c.a",true).

But I cannot think of a good way to exit the "chord.c.a" context when the next key is pressed. Something like onDidExecuteCommand (proposed in #1431) might work: if any command is run while in "chord.c.a" mode, then disable the mode.

Any suggestions?

@NightMachinery
Copy link

NightMachinery commented Feb 28, 2018

I very much like the Spacemacs.org model of things, and if multi key chords are supported, something similar can be achieved for VS code.

@truesilver92
Copy link

I bet it is possible to implement this using just a plugin that defines modes. As long as you use the plugin to actually do the command as well a normal command can be run while also clearing the key chord modes used to implement the key chords

@macintacos
Copy link

Just as a datapoint, but I find that with the VSpaceCode extension I have found the Spacemacs chord emulation that I was looking for 🙂. While I still really believe that this should be addressed, the need has dramatically dropped for me as far as I'm concerned. If you really like Spacemacs chords, check out that extension!

@zean11
Copy link

zean11 commented Nov 3, 2020

Just as a datapoint, but I find that with the VSpaceCode extension I have found the Spacemacs chord emulation that I was looking for 🙂. While I still really believe that this should be addressed, the need has dramatically dropped for me as far as I'm concerned. If you really like Spacemacs chords, check out that extension!

I too am using that extension and loving it. However this just makes a native implementation even more important to me, since it now showed me how good vscode can be with it.

Further reasons for a native implementation are many edge cases, where the plugin collection from vspacecode is not able to be activated. Or being able to search for a command and seeing the shortcut (chord) in the "ctrl+shift+p" menu.

So while it is indeed nice.. a native implementation would be nicer 😉 even for vspacecode

I just wanted to comment that so the prior on this ticket does not drop even further 😄

@truesilver92
Copy link

I am not seeing it on the description page, does vspacecode support mapping arbitrary length key chords?

@macintacos
Copy link

@truesilver92 you can map arbitrary key chord lengths by creating multiple menus. VSpaceCode's functionality for chords is actually implemented by the vscode-which-key extension (it's installed along with VSpaceCode; VSpaceCode is just a "default keychord map", if you will).

One limitation you should likely be away of is that I don't believe you can make multiple keychords that include modifiers, so something like ctrl+a ctrl+b ctrl+c is not possible, but you can make a chord that is SPC a b c (or any length, really). I recommend reading their documentation about it.

I still think that having 3+ chords available to folks who don't want to install that extension is very handy, and should still be implemented for sure! Limiting chords to 2 always felt.... arbitrary 🙂

@thiagomajesk
Copy link

I'm also interested in this, I think it would be a great addition. What's the requirement for getting this approved/ voted, etc?

@alexdima alexdima changed the title enable keychords of 3 steps enable keychords of 3 or more steps Oct 19, 2021
@spigelli
Copy link

This would need to check if the keyboard has n-key-rollover or limit at 6 keys right?

@truesilver92
Copy link

It shouldn't need that. It is called a "chord" but it is not intended for multiple segments to be pressed at the same time; at most all the modifiers and a single character.

@druskus20
Copy link

+1 This is the only thing I need to be able to port my Vim keymaps to vscode.

@AaronNGray
Copy link

AaronNGray commented Feb 19, 2022

The basic ChordKeybinding class has an Array of SimpleKeybinding's,
https://github.com/microsoft/vscode/blob/main/src/vs/base/common/keybindings.ts#131

theres other bits of code though that do not support this though such as :-
https://github.com/microsoft/vscode/blob/main/src/vs/base/common/keybindings.ts#L36
https://github.com/microsoft/vscode/blob/main/src/vs/monaco.d.ts#L422

Keybindings seem to be represented as numbers in places that should hopefully be able to be replace by number Arrays
https://github.com/microsoft/vscode/blob/main/src/vs/base/common/keybindings.ts#L36

Then there is the keybinding parser :-
https://github.com/microsoft/vscode/blob/main/src/vs/base/common/keybindingParser.ts#L10

And UI stuff :-
https://github.com/microsoft/vscode/blob/main/src/vs/base/browser/ui/keybindingLabel/keybindingLabel.ts#L26

Not sure if this is complete yet probably not, but it looks scalable and doable.

@AaronNGray
Copy link

AaronNGray commented Feb 20, 2022

Okay I see why this has not been done now, its quite complex ! I am going to attempt it over the next week.

@amirdib
Copy link

amirdib commented Jun 25, 2022

Also interested. Please ask if you need help @AaronNGray

@AaronNGray
Copy link

@amirdib Sorry I printed out the relevant code it’s several pages that would probably need totally reworking then got distracted by other tasks. I will look the printouts out again and have a fresh look at them.

@wmstack
Copy link

wmstack commented Jul 6, 2022

I bet it is possible to implement this using just a plugin that defines modes. As long as you use the plugin to actually do the command as well a normal command can be run while also clearing the key chord modes used to implement the key chords

I did make a plugin that enables you to have your own modes, at https://github.com/wmstack/contextually, though I still feel like three level chords are better implemented natively.

@vscodenpa vscodenpa added the unreleased Patch has not yet been released in VS Code Insiders label Mar 20, 2023
@alexdima alexdima modified the milestones: Backlog, March 2023 Mar 20, 2023
@vscodenpa vscodenpa added insiders-released Patch has been released in VS Code Insiders and removed unreleased Patch has not yet been released in VS Code Insiders labels Mar 21, 2023
@ulugbekna
Copy link
Contributor

verification steps:

  1. Add keybindings to your keybindings.json (this feature is currently supported only via keybindings.json, not the UI) -- you can invoke "Open Keyboard Shortcuts (JSON)" [1]
  2. Add keybindings with 1, 2, 3 (or more) chords (chord = simultaneous press of one or more keys, e.g., "cmd+shift+p")
  3. Make sure those keybindings work

[1] How to add a keybinding (if you're not familiar)

contents of your keybindings.json can look like this:

[
	{ // hide or show all help-bars
		"key": "ctrl+h",
		"command": "runCommands", 
		"args": {
			"commands": [
				"workbench.action.toggleSidebarVisibility",
				"workbench.action.toggleActivityBarVisibility",
				"workbench.action.toggleAuxiliaryBar"
			]
		}
	},
	{ // create a new file and prefill with header
		"key": "ctrl+n ctrl+t",
		"command": "runCommands",
		"args": {
			"commands": [
				{
					"command": "workbench.action.files.newUntitledFile",
					"args": {
						"languageId": "typescript"
					}
				},
				{
					"command": "type",
					"args": {
						"text": "/*---------------------------------------------------------------------------------------------\n"
					}
				},
				{
					"command": "type",
					"args": {
						"text": " *  Copyright (c) Microsoft Corporation. All rights reserved.\n"
					}
				},
				{
					"command": "type",
					"args": {
						"text": " *  Licensed under the MIT License. See License.txt in the project root for license information.\n"
					}
				},
				{
					"command": "type",
					"args": {
						"text": "-------------------------------------------------------------------------------------------*/\n\n"
					}
				},
			]
		}
	},
	{ 
		"key": "ctrl+t ctrl+p ctrl+v",
		"command": "workbench.action.toggleAuxiliaryBar",
	},
	{ 
		"key": "ctrl+a ctrl+b ctrl+v ctrl+alt+b",
		"command": "workbench.action.toggleActivityBarVisibility",
	}
]

@ulugbekna ulugbekna added the verification-needed Verification of issue is requested label Mar 21, 2023
@Tyriar
Copy link
Member

Tyriar commented Mar 21, 2023

Very cool!

@Tyriar Tyriar added the verified Verification succeeded label Mar 21, 2023
@LaurensUP
Copy link

Wow.. so happy I found this -- thank you!
I believe it's missing from the official documentation?

@ulugbekna
Copy link
Contributor

I believe it's missing from the official documentation?

Indeed, I will update the docs soon

@LaurensUP
Copy link

@ulugbekna thank you!
It's working brilliantly and smoothly. Absolutely awesome feature!! 🙏

@ulugbekna
Copy link
Contributor

This was actually developed by @ dyedgreen
All credits goes to him :-)

@github-actions github-actions bot locked and limited conversation to collaborators May 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality insiders-released Patch has been released in VS Code Insiders keybindings VS Code keybinding issues verification-needed Verification of issue is requested verified Verification succeeded
Projects
None yet
Development

Successfully merging a pull request may close this issue.