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

[Deferred to 0.8 Release] Empty HTML/JSX tags

Open r-malm opened this issue 1 year ago • 6 comments

Checklist

  • [x] Have you read through :h nvim-surround to see if there might be any relevant information there?

Is your feature request related to a problem? Please describe. I use React Fragments quite a lot. It would nice if I could produce those empty tags with this plugin. It's the only thing I'd like to have before completely moving over to this plugin from tpope's Surround.

Describe the solution you'd like Typing > after the Enter an HTML tag: input would result in the empty tags (like in the aforementioned tpope plugin, but might feel a bit weird with the current input text). Leaving the tag input empty could be another option.

r-malm avatar Jul 13 '22 10:07 r-malm

I'm not really that familiar with React Fragments (it might be useful if you could show an example of what you want?), but it looks like this should achieve want you want?

require("nvim-surround").buffer_setup({
    delimiters = {
        pairs = {
            ["F"] = { "<>", "</>" },
        },
    },
})

That ends a buffer-specific surround; just pop this in after/ftplugin/typescript.lua or similar and surround with ys<text object>F

andrewferrier avatar Jul 13 '22 13:07 andrewferrier

I think that @andrewferrier's answer should work properly for this use case, although I think the point is to "concentrate" all tag-related queries into as few (mental) groups as possible, e.g. ys[object]t<CR> instead of ys[object]F. I'll look into vim.fn.input() and see if there's a way to distinguish between an empty input string and actually cancelling the input (e.g. via <C-c> or <Esc>).

kylechui avatar Jul 13 '22 15:07 kylechui

I'll need to do a "hack" of sorts if this issue truly is a problem upstream, but I think it should still be doable.

kylechui avatar Jul 14 '22 00:07 kylechui

Looks like they just merged it into main! I'm hesitant on making the latest nightly a requirement for this plugin (yet). If you really want this feature, I can probably bodge something together for the time being, and then switch to the "clean" solution once 0.8 arrives

kylechui avatar Jul 14 '22 08:07 kylechui

Great! I can certainly wait until 0.8 becomes stable, so it's up to you how you want to handle this. 😺

r-malm avatar Jul 14 '22 08:07 r-malm

Thanks for your patience; just a reminder that Andrew's surround exists in case you do want something that works in the meantime, although slightly differently

kylechui avatar Jul 14 '22 09:07 kylechui

Also why would we want to type > when we could simply press <enter> to finish the empty tag?

Invertisment avatar Aug 05 '22 15:08 Invertisment

@Invertisment Many vim-surround users are used to typing ysiw<div>, and having that automatically insert the tag, instead of ysiwtdiv<CR>. It's mostly a matter of taste.

kylechui avatar Aug 05 '22 16:08 kylechui

@r-malm This is available on the latest commit in main by entering ys[motion]t and then directly hitting <CR> instead of entering any text.

kylechui avatar Aug 07 '22 00:08 kylechui