The vscode vim extension does not write real characters?

Viewed 208

I have customized the vim-extension in vscode, and for most modes, it executes commands correctly. However If I try to write actuall characters (which are thus no longer commands), it won't. Why is that?

Example:

"vim.insertModeKeyBindingsNonRecursive": [
        {
            "before": [
                "<leader>",
                "o"
            ],
            "after": [
                "<Esc>",
                "i",
                "Abcd"
            ]
        },
]

This should only write Abcd, because before that sequence is i, switching into insert mode. (So the <Esc> -> i, is redundant, it is here just as example). The vscode vim extension executes the <Esc> and also the i (becuase I know after that command I am back in insert mode), but will not print the Abcd. Why? Is the extension configured just to execute commands and not to actually print something? How to enable that?

2 Answers

It looks like you just need to split each character of the "Abcd" on to a separate line:

"vim.insertModeKeyBindingsNonRecursive": [
    {
        "before": [
            "<leader>",
            "o"
        ],
        "after": [
            "<Esc>",
            "i",
            "A",
            "b",
            "c",
            "d"
        ]
    },
]

As mentioned in the documentation of the project, you are supposed to pass a single key character (single character for normal key and multiple characters for special keys such as arrow keys or escape keys).

Updating after value will solve the issue:

"after": [
    "<Esc>",
    "i",
    "A", "b", "c", "d"
]

You can take a look at the internals of the plugin to understand why it is not working with multiple characters passes in here, specifically NormalizeKey function, which would wrap any string with multiple characters with <>.

Related