Search code examples
vimvim-plugin

With vim what is the best way to select an xml block?


I would like to select the all <div>

     <div>
      ^cursor
        <p>
          currsor
          Issues reported by division from the
          <a href="https://re.fr"> https://re.fr</a>
            they will create an issue.
        </p>
      </div>

The best I found so far is:

V/div<Enter>n

or

Vjjjjjjj

but we have to count lines what is annoying.

I would like to use the fact that this is well formed XML so we know which tag close which tag.

PS: I have vim-surround-plugging installed


Solution

  • Text objects are introduced in chapter 4 of the user manual and further listed under :help text-objects, where this is very easy to find:

    at    "a tag block", select [count] tag blocks, from the
          [count]'th unmatched "<aaa>" backwards to the matching
          "</aaa>", including the "<aaa>" and "</aaa>".
          See |tag-blocks| about the details.
          When used in Visual mode it is made characterwise.