nvim-surround
nvim-surround copied to clipboard
[Deferred to 0.8 Release] Empty HTML/JSX tags
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.
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
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>
).
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.
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
Great! I can certainly wait until 0.8 becomes stable, so it's up to you how you want to handle this. 😺
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
Also why would we want to type >
when we could simply press <enter>
to finish the empty tag?
@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.
@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.