14

I'm wondering if anybody knows of a Vim plugin that can handle cursor movement between parent/child/sibling elements on either HTML or XML files (preferably both).

2 Answers 2

16

I like to use the default movement and (visual) text objects

 vatatzc   # create a fold for second parent tag with all child elements

 yit6jvitp # yank this element child nodes and, 6 lines down, 
           # replace the element content with the yanked text
Sign up to request clarification or add additional context in comments.

3 Comments

thanks to your answer I have discovered something huge : you can chain text objects !
Jup. That was a gem when I discovered it myself :)
Everything I thought I knew about vim was a lie, and I no longer fear the darkness.
6

Matchit.vim does some of what you want. It jumps between opening and closing XML/HTML tags when you press the % key. But there are some tags where it adds a special behaviour. For example, if your cursor is on a <ul> tag, pressing % will move your cursor forward to the next <li> tag, and so on until you reach the closing </ul> tag where % causes you to jump back to the opening tag.

Matchit is distributed with Vim, so you don't have to install it. But you do have to enable it by putting this in your vimrc file:

runtime macros/matchit.vim

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.