Vim icon indicating copy to clipboard operation
Vim copied to clipboard

Keybindings with Alt modifier.

Open tesq0 opened this issue 7 years ago • 22 comments

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 ?

tesq0 avatar Jun 07 '18 14:06 tesq0

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

jpoon avatar Jun 08 '18 07:06 jpoon

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

tesq0 avatar Jun 08 '18 10:06 tesq0

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.

Cybolic avatar Mar 26 '19 13:03 Cybolic

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

kascote avatar Apr 05 '19 15:04 kascote

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

jpoon avatar May 06 '19 07:05 jpoon

Is this something that can be implemented?

nmoagit avatar May 26 '19 01:05 nmoagit

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.

david avatar Jul 19 '19 19:07 david

+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

thisisrandy avatar Oct 18 '19 00:10 thisisrandy

image

ocoka avatar Apr 19 '20 08:04 ocoka

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?

detj avatar Nov 18 '20 19:11 detj

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"
    },

berknam avatar Nov 20 '20 12:11 berknam

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

detj avatar Nov 20 '20 13:11 detj

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

J-Fields avatar Nov 20 '20 19:11 J-Fields

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.

berknam avatar Nov 20 '20 19:11 berknam

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

ownself avatar Mar 05 '21 16:03 ownself

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

ocoka avatar Mar 05 '21 16:03 ocoka

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.

adelin-b avatar Mar 19 '22 13:03 adelin-b

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

cognivore avatar Jan 14 '23 01:01 cognivore

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"?

rtviii avatar Jan 16 '23 08:01 rtviii

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

4c74356b41 avatar Nov 01 '23 09:11 4c74356b41

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

ownself avatar Jul 13 '24 14:07 ownself

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"]
    }, 

julia-script avatar Aug 28 '24 13:08 julia-script