The Computer Oracle

How to navigate between begin and end html tag in Vim?

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 5

--

Chapters
00:00 How To Navigate Between Begin And End Html Tag In Vim?
00:15 Accepted Answer Score 10
00:50 Answer 2 Score 18
02:25 Thank you

--

Full question
https://superuser.com/questions/189815/h...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#vim #html #gvim

#avk47



ANSWER 1

Score 18


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.


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:




ACCEPTED ANSWER

Score 10


The matchit.vim plugin, in conjunction with the html.vim filetype plugin, will allow you to do this. One way to load the matchit.vim plugin is to put this in your ~/.vimrc:

runtime macros/matchit.vim

If you don't already have filetype plugins enabled, also put this in in your ~/.vimrc:

filetype plugin on

Then when you edit an HTML file, you can jump from a tag to the matching tag by typing %. You can find out more by executing

:help matchit