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

FR: Automatically close HTML tags with `S` visual surround #56

Closed marcelarie closed 2 years ago

marcelarie commented 2 years ago

Checklist

Describe the solution you'd like Using Si on visual mode gives the option to add a left and a right pair. This is cool but not useful for all the cases, sometime I just want to add the first pair, so the second closes automatically, like for example with HTML tags. Using the default S surround, I can only write 1 character.

I think the completion of the first pair should "finish" once the user presses enter to confirm the pair. For example:

When pressing S on visual mode:

<html>Enter

Then the right pair will be automatically closed with </html>.

Additional context

https://user-images.githubusercontent.com/62728887/178730409-dfb77456-056e-4ffe-bd94-c6e03e82c431.mov

marcelarie commented 2 years ago

It would be even nicer if the user could add custom pairs and the "auto closing" feed from those pairs.

For example:

    delimiters = {
        pairs = {
            ["("] = { "( ", " )" },
            [")"] = { "(", ")" },
            ["<custom>"] = { "<custom>", "</custom>" },
        },
-- ...

of course, HTML tags can be automatically matched with all the cases that use <.*>, it is just an example.

marcelarie commented 2 years ago

I just realized there is a "t" option for HTML tags 😅