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

Keybindings with Alt modifier. #2713

Open
tesq0 opened this issue Jun 7, 2018 · 22 comments · May be fixed by #8803
Open

Keybindings with Alt modifier. #2713

tesq0 opened this issue Jun 7, 2018 · 22 comments · May be fixed by #8803

Comments

@tesq0
Copy link

tesq0 commented Jun 7, 2018

FEATURE REQUEST

I would like to be able to bind key sequences with alt to vim keys, specifically Alt + v to V like so:

{ "before": [ "alt+v" ], "after": [ "V" ], },

Would this be hard to implement ?

@jpoon
Copy link
Member

jpoon commented Jun 8, 2018

We support this already. Have you tried using the alt key when configuring your remapping? https://github.com/VSCodeVim/Vim#key-remapping

@jpoon jpoon closed this as completed Jun 8, 2018
@tesq0
Copy link
Author

tesq0 commented Jun 8, 2018

Here's what i have tried. This setting seems to have no effect. :

    "vim.otherModesKeyBindingsNonRecursive": [
        {
            "before": ["alt+v"],
            "after": ["V"]
        }
    ],

It appears to not capture the alt key at all. When i try to bind any other alt combination like "alt+x", or just "alt" to any other command like so:

"vim.otherModesKeyBindingsNonRecursive": [
    {
        "before": ["alt+x"],
        "after": [],
        "commands": [
            {
                "command": "workbench.action.showCommands",
                "args": []
            }
        ]
    }
]

It also wouldn't work. Using other modifier keys like "<c-x>" worked.

Here are some options in my configuration that may me worth mentioning:

    "window.menuBarVisibility": "hidden",
    "window.enableMenuBarMnemonics": false,

Environment

VSCode version: 1.24.0
VSCode commit: 6a6e02cef0f2122ee1469765b704faf5d0e0d859
OS: Windows 10 Pro x64
Extension version: v0.12.0

@Cybolic
Copy link

Cybolic commented Mar 26, 2019

I have the same issue on Linux (arch). Enabling debugging, I can see that keys using the alt modifier are not captured at all, i.e. does not print any Remapper: debug: trying to find matching remap lines.

@kascote
Copy link

kascote commented Apr 5, 2019

Same issue on Linux (ubuntu)
Other findings may be related or not.
with Debug enabled:

  • do not log any ALT key combination
  • do not log ctrl+h or ctrl+l (defined on package.json), but works
  • log ctrl+pageUp and ctrl+pageDown (defined on package.json), works

Environment

Version: 1.33.0
Commit: 0dd516dd412d42323fc3464531b1c715d51c4c1a
Date: 2019-04-04T15:08:57.775Z
Electron: 3.1.6
Chrome: 66.0.3359.181
Node.js: 10.2.0
V8: 6.6.346.32
OS: Linux x64 4.15.0-47-generic

@jpoon
Copy link
Member

jpoon commented May 6, 2019

I was mistaken. We don't bind to alt. See the second bullet point of https://github.com/VSCodeVim/Vim#debugging-remappings.

@nmoagit
Copy link

nmoagit commented May 26, 2019

Is this something that can be implemented?

@david
Copy link

david commented Jul 19, 2019

Bump. Any chance of implementing this? My leader key is usually alt-space, which lets me use it in any mode, including insert mode, and even outside the editor.

@thisisrandy
Copy link
Contributor

+1
A common use case is A-j/A-k for moving lines. It's annoying to have to use the arrow keys for this in VSCode, which has the same mapped to A-down/A-up. I poked around in the code for a bit trying to figure out where captured keys are defined, but I've spent too long at this point to want to do it on my own. Please reopen

@ocoka
Copy link

ocoka commented Apr 19, 2020

image

@detj
Copy link

detj commented Nov 18, 2020

A common use case is A-j/A-k for moving lines. It's annoying to have to use the arrow keys for this in VSCode, which has the same mapped to A-down/A-up. I poked around in the code for a bit trying to figure out where captured keys are defined, but I've spent too long at this point to want to do it on my own. Please reopen

I have the exact need. <A-k>/<A-j> for moving lines up/down. Will adding the keybinding in package.json enable this?

@berknam
Copy link
Contributor

berknam commented Nov 20, 2020

The problem with binding to alt+... key combinations is that it would make those combinations stop working for their normal behavior and there is a lot of alt+... that are either used by default vscode commands or by other extensions.

If we bound to those key combos we would enter in conflict with the commands of those other extensions. This would happen even if the user wasn't using those key combos for any remap.

It might be possible to only bind to those key combos when a remap that uses it is configured. But it would still conflict if there was the same key combo being used by another extension.

For now as a workaround for moving lines with <A-j> and <A-k> you can add this to your 'keybindings.json' file:

    {
        "key": "alt+j",
        "command": "editor.action.moveLinesDownAction",
        "when": "editorTextFocus && !editorReadonly && vim.active"
    },
    {
        "key": "alt+k",
        "command": "editor.action.moveLinesUpAction",
        "when": "editorTextFocus && !editorReadonly && vim.active"
    },

@detj
Copy link

detj commented Nov 20, 2020

@berknam hmm. makes sense. I have added the above custom keyboard shortcuts and they gel nicely. thanks.

@J-Fields
Copy link
Member

We should probably provide bindings like these but set their default values in handleKeys to false.

@berknam
Copy link
Contributor

berknam commented Nov 20, 2020

We should probably provide bindings like these but set their default values in handleKeys to false.

That's a great option! Should be simple enough to do.

@ownself
Copy link

ownself commented Mar 5, 2021

I came here one year ago, and yet it's still the reason rejecting me from VSCode.... :(

@ocoka
Copy link

ocoka commented Mar 5, 2021

One year is relative small amount of time for Microsoft )
In 2010 I was newbie in programming, and has an order for .NET, I made it, but it is was a pain, and I was switched total to frontend development , it was like a gulp of fresh air, coding flow goes easily, time was going and ..tada.. Microsoft gets GitHub, had buried Atom, and born VSCode... Welcome back devil says

@adelin-b
Copy link

This feature is so important. Being able to remap a-l to right or a-h to left prevent to have to press enter just for movin a stupid char on the side during a typo or some scope movements.

khollbach added a commit to khollbach/config-files that referenced this issue Aug 16, 2022
Update vimrc to try to get vscode to use my mappings for switching
splits (alt + i/j/k/l). Unfortunately, it doesn't work, because vscode
doesn't handle mappings that use alt. See:
VSCodeVim/Vim#2713

TODO: try to figure out a workaround; maybe see the above thread for
ideas.
@cognivore
Copy link

Hello, friends.
If anyone would share their experience about working with and Alt-left to call "Go Back"?
What about Alt+] in Co-Pilot option selection?

@rtviii
Copy link

rtviii commented Jan 16, 2023

Yeah this is a glaring hole in the space of useful mod keys. I would happily toss out all the other conflicting extensions (insofar as i understand @berknam ) if that would give me the Alt key for binding. Is there chance you can add "hard-override"?

@4c74356b41
Copy link

i actually have the inverse, after re-installing vscode from scratch vim intercepts alt+shift and i dont see any way to disable this. ie alt+shift+up\down

@HyunggyuJang HyunggyuJang linked a pull request Jan 1, 2024 that will close this issue
HenryTSZ added a commit to HenryTSZ/NVim that referenced this issue Mar 5, 2024
@ownself
Copy link

ownself commented Jul 13, 2024

Well, I come here again, and finally find out that 5 years later, eventually it had been fixed : Remapping more complex key combinations!

@julia-script
Copy link

The problem with binding to alt+... key combinations is that it would make those combinations stop working for their normal behavior and there is a lot of alt+... that are either used by default vscode commands or by other extensions.

If we bound to those key combos we would enter in conflict with the commands of those other extensions. This would happen even if the user wasn't using those key combos for any remap.

It might be possible to only bind to those key combos when a remap that uses it is configured. But it would still conflict if there was the same key combo being used by another extension.

For now as a workaround for moving lines with <A-j> and <A-k> you can add this to your 'keybindings.json' file:

    {
        "key": "alt+j",
        "command": "editor.action.moveLinesDownAction",
        "when": "editorTextFocus && !editorReadonly && vim.active"
    },
    {
        "key": "alt+k",
        "command": "editor.action.moveLinesUpAction",
        "when": "editorTextFocus && !editorReadonly && vim.active"
    },

This also works on mac at least

    {
      "before": ["∆"],
      "commands": ["editor.action.moveLinesDownAction"]
    }, 
    {
      "before": ["˚"],
      "commands": ["editor.action.moveLinesUpAction"]
    }, 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.