Jump to matching XML tags in Vim

后端 未结 4 547
别那么骄傲
别那么骄傲 2020-12-07 07:19

Vim % operator jumps to matching parentheses, comment ends and a few other things. It doesn\'t, however, match XML tags (or any other tag, to the best of my kn

4条回答
  •  春和景丽
    2020-12-07 07:58

    You can do this without additional plugins:

    • place cursor on the tag
    • vat - will select the (outer) tag and place cursor on the end
    • once you've got your selection you can toggle between the top and bottom with o (update based on Michael Gruber's note)
    • c - change or, y - copy or, escape for leaving visual mode ...

    Another useful operation is: vit - will select content of the tag (inner).

    Update (thanks to @elrado) Example: vito will enable you to select inner content of the tag and position cursor on the beginning of the selected text.

    Reference: https://superuser.com/questions/182355/how-can-i-select-an-html-tags-content-in-vim

    Vim reference (thanks to @Geek for noting this out):

    :help visual-operators
    

    you'll get:

    4. Operating on the Visual area             *visual-operators*
    
    The objects that can be used are:
        ...
        at  a   block (with tags)        |v_at|
        it  inner   block            |v_it|
        ...
    

提交回复
热议问题