VIM jump from one xml tag to the closing one

9,998

Solution 1

  • Install the matchit plugin (see :help matchit-install for instructions).
  • Make sure automatic file-type detection and plugin-loading is enabled (:filetype plugin on).

Henceforth, whenever you edit a file detected as xml or html or some other tag-based markup language, the combination of the matchit plugin and the filetype plugin files will allow the % motion to match open and close tags.

Solution 2

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:

Share:
9,998

Related videos on Youtube

daisy
Author by

daisy

Updated on September 18, 2022

Comments

  • daisy
    daisy over 1 year

    Is there a shortcut to jump from , e.g <XX> to </XX> ?

    I already give it a try with '%' , but it doesn't work for this situation.

    • Admin
      Admin about 12 years
      I think you'll need a plugin like matchit in order to be able to match XML tags. matchit itself seems to come with most vim distributions, but you'll still have to enable it yourself. :help matchit-install for more.
    • Admin
      Admin over 9 years