Vim: Keybindings with Alt modifier.

Created on 7 Jun 2018  路  14Comments  路  Source: VSCodeVim/Vim

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 ?

Most helpful comment

+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

All 14 comments

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

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

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

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.

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

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

Is this something that can be implemented?

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.

+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

image

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?

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 hmm. makes sense. I have added the above custom keyboard shortcuts and they gel nicely. thanks.

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

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

spinningarrow picture spinningarrow  路  3Comments

orn688 picture orn688  路  3Comments

lucastheisen picture lucastheisen  路  3Comments

ghost picture ghost  路  3Comments

AndersenJ picture AndersenJ  路  3Comments