nvim-surround icon indicating copy to clipboard operation
nvim-surround copied to clipboard

Use the appropriate replacement function for aliases

Open haoming-li-ling opened this issue 2 years ago • 3 comments

I have an alias for two surrounds, both of which have replacement functions defined in the change table. When I invoke a change of surrounds (cs<alias>) with the alias, however, neither replacement function is applied, and the behavior falls back to waiting for a single surround character. I think the desired behavior should be to apply the replacement that belongs to the actual surrounds triggered by the alias in the context.

haoming-li-ling avatar Aug 14 '22 12:08 haoming-li-ling

Can you provide an example of what is exactly the problem? Like your setup function + buffer + keymap combo?

kylechui avatar Aug 14 '22 16:08 kylechui

Sample config:

require("nvim-surround").setup({
    surrounds = {
        [")"] = {
            change = {
                replacement = { "(", ")" },
            },
        },
        ["}"] = {
            change = {
                replacement = { "{", "}" },
            },
        },
    },
    aliases = {
        ["o"] = { ")", "}" },
    },
})

Buffer:

{(test)}

The keymap cso shouldn't wait for another keypress, but should directly trigger the replacement key.

kylechui avatar Aug 14 '22 17:08 kylechui

Note to self: When computing nearest selection, return which character from the alias table was actually used to find the selections.

kylechui avatar Aug 14 '22 17:08 kylechui

Closing this as it seems to incur high cost for little utility, and is related to #98.

kylechui avatar Feb 09 '23 17:02 kylechui