Navigating HTML tags in Vim
You can jump between tags using visual operators, in example:
- Place the cursor on the tag.
- Enter visual mode by pressing v.
- 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:
- How to jump between matching HTML/XML tags? at Vim SE
- Jump to matching XML tags in Vim at stackoverflow SE
- How can I find the close html tag quickly in vim? at stackoverflow SE
- How to navigate between begin and end html tag? at superuser SE
- VIM jump from one xml tag to the closing one at Unix SE
- How can I select an html tag's content in Vim? at superuser SE
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