Vim: visualModeKeyBindingsNonRecursive and visualModeKeyBindings don't work for first key pressed after visual mode is entered

Colemak users remap hjkl to snei (as hjkl are in ridiculous places using our keyboard layout).

Here is a config representing how we remap the n key and can be used to reproduce this issue using the subsequent steps:

"vim.visualModeKeyBindingsNonRecursive": [
  { "before": "n", "after": "j" }
],

With this config if you type vnn the first n acts as if n hasn’t been remapped to j and jumps to the “next match”. After this n works as expected (so the second n there cause a down movement). I can also do:

v<left-arrow>n and then n will come out fine. So it’s only for the very first key-press after visual mode has been entered.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 10
  • Comments: 19 (15 by maintainers)

Most upvoted comments

Yep, thanks for pointing that out @hioki-daichi. After doing a bit of research, this seems inline with the behaviour for vanilla vim. If that conclusion is incorrect, let me know.

I think this issue was ultimately resolved with https://github.com/VSCodeVim/Vim/pull/3424 and with https://github.com/VSCodeVim/Vim/pull/3440, I’ll be adding some validation around the remap to ensure that a string array is used.

@jpoon The minimal config to reproduce this is:

"vim.visualModeKeyBindingsNonRecursive": [
  { "before": "n", "after": "j" }
],

then just follow the instructions in the issue description.

Hi, I installed vscodevim these days and the “problem” is still there, as described. When you remap a char in visual mode, it does not work on the first keypress after entering visual mode. The workaround with timeout is not really feasible, because it practically disables any user defined mapping with two keystrokes (you have no chance to type it fast enough). However, I have found a workaround by luck. You simply map v to itself in normal Mode and then it works: { "before": ["v"], "after": ["v"] },

@jpoon here’s mine:

    "vim.insertModeKeyBindings": [
        {
            "before": [
                "k",
                "j"
            ],
            "after": [
                "<Esc>"
            ]
        }
    ],
    "vim.visualModeKeyBindings": [
        {
            "before": [
                "<space>"
            ],
            "commands": [
                {
                    "command": "workbench.action.toggleZenMode",
                    "args": []
                }
            ]
        },
        {
            "before": [
                "H"
            ],
            "after": [
                "^"
            ]
        },
        {
            "before": [
                "J"
            ],
            "after": [
                "G"
            ]
        },
        {
            "before": [
                "L"
            ],
            "after": [
                "$"
            ]
        },
        {
            "before": [
                "K"
            ],
            "after": [
                "g",
                "g"
            ]
        },
        {
            "before": [
                "Tab"
            ],
            "after": [
                "%"
            ]
        }
    ],
    "vim.normalModeKeyBindings": [
        {
            "before": [
                "U"
            ],
            "after": [
                "<ctrl+r>",
            ]
        },
        {
            "before": [
                "<space>"
            ],
            "commands": [
                {
                    "command": "workbench.action.toggleZenMode",
                    "args": []
                }
            ]
        },
        {
            "before": [
                "H"
            ],
            "after": [
                "^"
            ]
        },
        {
            "before": [
                "J"
            ],
            "after": [
                "G"
            ]
        },
        {
            "before": [
                "L"
            ],
            "after": [
                "$"
            ]
        },
        {
            "before": [
                "K"
            ],
            "after": [
                "g",
                "g"
            ]
        },
        {
            "before": [
                "tab"
            ],
            "after": [
                "%"
            ]
        }
    ],