3

Is there a plugin or a way to work with HTML text objects, e.g.

Say the cursor is in one of the attributes below:

<div data-foo="bar baz caz" class="a b c">

I wish to treat data-foo="bar baz caz" or class="a b c" as text objects, e.g. change inner attribute group, or change a attribute group.

1 Answer 1

4

The vim-textobj-xmlattr plugin does exactly that.

This vim plugin provides two text objects: ax and ix. They represent XML/HTML attributes.

ix works with the inner attribute, with no surrounding whitespace. ax works like aw does: it includes the whitespace before the attribute. I know that aw includes the whitespace after/before or whatever it finds more fitty, but XML/HTML attributes always include whitespace before them, while they do not always include whitespace after.

1
  • GAME CHANGER!!! Most awesomeness!!!!!!!!!!!!!!!!!!!!!!! Thank you kind sir! Commented Sep 14, 2022 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.