How can I jump to the next sibling of an XML element with Vim? How can I jump to the next sibling of an XML element with Vim? xml xml

How can I jump to the next sibling of an XML element with Vim?


They obviously don't satisfy all your requirements but these crude commands may help…

/^\s\{<C-r>=indent(".")<CR>}<\w\+\s<CR>?^\s\{<C-r>=indent(".")<CR>}<\w\+\s<CR>

Jump forward/backward to the next XML tag at the same indentation level.


If you need this motion often, it makes sense to create a custom motion for it. With my CountJump plugin, this is very easy:

call CountJump#Motion#MakeBracketMotion('<buffer>', '', '', '<Child', '<Child.*\zs/>\|</Child>', 0)

This will modify the [[ [] etc. motions (you can also choose other mappings), and supports a count, too. (Put this into e.g. ~/.vim/ftplugin/xml_motions.vim.)


I would probably just adjust the folding (you can turn on XML folding with let g:xml_syntax_folding = 1 and setlocal foldmethod=syntax) so that the child elements are all folded (e.g. zMzr). Then, navigation to childs is a simple "N line(s) up/down" with j / k.