tpope / vim-surround

surround.vim: Delete/change/add parentheses/quotes/XML-tags/much more with ease
https://www.vim.org/scripts/script.php?script_id=1697
13.39k stars 444 forks source link

Feature request: Treat self-closing XML/HTML tags as <> #376

Closed ebrannin-bw closed 1 year ago

ebrannin-bw commented 1 year ago

Steps to reproduce

  1. Make a new document:
    <outer>
    <inner />
    </outer>
  2. Put the cursor in the middle of <inner />: /inn
  3. Type ysat<middle> (not shown below) or `ysat<C-T>middle> (shown)

Expected result:

<outer>
<middle>
  <inner />
</middle>
</outer>

Observed result

<middle>
  <outer>
  <inner />
  </outer>
</middle>

Workaround

ysa<<middle> or ysa<<C-T>middle>

Background

Self-closing tags come up in HTML5, XML, React, etc.

I was just turning a React component from a flex-row into a table, and as I wrapped each element with <td> I had to switch between ysat and ysa< depending on if it was self-closing or not.

tpope commented 1 year ago

I think I agree. However, surround.vim is merely delegating to Vim's built-in at operator. You can see the same behavior if you do dat or gUat.

And I don't plan on breaking with Vim here. You could try floating your proposal to Vim itself, but I doubt it would be considered due to backwards compatibility concerns.

ebrannin-bw commented 1 year ago

Makes sense, thanks!

ebrannin-bw commented 1 year ago

Looks like vim has already documented this:

"<aaa/>" items are skipped. Case is ignored, also for XML where case does matter.

Sounds like what I really want is a custom text-object plugin to declare something like aT and iT (or whatever, but it seems like those aren't built-in) -- I'll update here if I find one already exists or (very eventually) figure out how to write one.

tpope commented 1 year ago

Sounds like what I really want is a custom text-object plugin

Yes, but see #355.

tpope commented 1 year ago

Oops, I meant to link to https://github.com/tpope/vim-surround/issues/329#issuecomment-922978875.