Navigating HTML tags in Vim

HtmlVim

Html Problem Overview


I would like to be able to navigate through HTML tag by tag. Is there a way I can move from HTML tag to tag. (i.e. *<div>hi</div><div>bye</div> ---> <div>hi</div>*<div>bye</div> I know about cit and cat, which is why I would imagine this is possible. Thanks!

Html Solutions


Solution 1 - Html

You can jump between tags using visual operators, in example:

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

Your cursor should jump forward to the matching closing html/xml tag. To jump backwards from closing tag, press o or O to jump to opposite tag.

Now you can either exit visual by pressing Esc, change it by c or copy by y.


To record that action into register, press qq to start recording, perform tag jump as above (including Esc), press q to finish. Then to invoke jump, press @q (to repeat, hit @@).


See more help at :help visual-operators or :help v_it:

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


Alternatively use plugin such as matchit.vim (See: Using % in languages without curly braces).


See also:

Solution 2 - Html

The matchit.vim macro gets you most of the way there, allowing you to move to a closing tag with % as you would matching parens or braces. It's included in many Vim distributions including the standard download, but often not enabled by default.

http://www.vim.org/scripts/script.php?script_id=39

Solution 3 - Html

Press F+>, then ; or , to move around. When you're got there, press a (lowercase) to go to insert mode after cursor.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmazlixView Question on Stackoverflow
Solution 1 - HtmlkenorbView Answer on Stackoverflow
Solution 2 - HtmlMichael BerkowskiView Answer on Stackoverflow
Solution 3 - Htmltr4ndatView Answer on Stackoverflow