49

Is it possible to select an HTML tag's content in Vim?

For example:

<p>I am a silly butterfly</p>

I would like to select "I am a silly butterfly".

I know that you can use vi" to select text inside quotes, brackets, etc. The problem here is that the text inside the HTML tags is not really within anything that I can use the i function for.

TTM
  • 239
  • 1
  • 9
fholgado
  • 593
  • 1
  • 4
  • 6

3 Answers3

84

You can use vit to visually select text in a tag. See

:help v_it
garyjohn
  • 34,610
  • 8
  • 97
  • 89
12

Here are the steps:

  1. Place the cursor on the tag.
  2. Enter Visual mode by pressing v.
  3. Select the inner tag block by pressing i+t (or a+t for outer tag block).

at a <tag> </tag> block (with tags)

it inner <tag> </tag> block

See more at "How to jump between matching HTML/XML tags?".

kenorb
  • 24,736
  • 27
  • 129
  • 199
1

If the format is well indent like this,

<div>
  <p>
    I am a silly butterfly
  </p>
  <p>
    I am a silly butterfly
  </p>
</div>

You use can vim-indent-object plugin, and type vii

foxiris
  • 111
  • 2