kylechui / nvim-surround

Add/change/delete surrounding delimiter pairs with ease. Written with :heart: in Lua.
MIT License
3.18k stars 62 forks source link

Use the appropriate replacement function for aliases #139

Closed haoming-li-ling closed 1 year ago

haoming-li-ling commented 2 years ago

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.

kylechui commented 2 years ago

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

kylechui commented 2 years ago

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 commented 2 years ago

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

kylechui commented 1 year ago

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