how can I find the close html tag quickly in vim?

前端 未结 4 1482
青春惊慌失措
青春惊慌失措 2020-12-28 17:04

Just like editing C source file, I can press % to get the closing } for the current cursor\'s {. How can I do this when editing html files? Is there any shortcuts? To be cle

相关标签:
4条回答
  • 2020-12-28 17:29

    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:

    • How to jump between matching HTML/XML tags? at Vim SE
    • Jump to matching XML tags in Vim at stackoverflow SE
    • Navigating HTML tags in Vim at stackoverflow SE
    • How to navigate between begin and end html tag? at superuser SE
    • VIM jump from one xml tag to the closing one at Unix SE
    • How can I select an html tag's content in Vim? at superuser SE
    0 讨论(0)
  • 2020-12-28 17:31

    MatchTagAlways is a plugin that always highlights the XML/HTML tags that enclose your cursor location.

    https://github.com/Valloric/MatchTagAlways

    0 讨论(0)
  • 2020-12-28 17:37

    I have had problems with this is the past, even with the matchit plugin. The way I solved it was to modify b:match_words on xml-type files. Here is the relevant section from my .vimrc:

      autocmd FileType html let b:match_words = '<\(\w\w*\):</\1,{:}'
      autocmd FileType xhtml let b:match_words = '<\(\w\w*\):</\1,{:}'
      autocmd FileType xml let b:match_words = '<\(\w\w*\):</\1,{:}'
    

    Try it out, see if it helps any.

    0 讨论(0)
  • 2020-12-28 17:46

    You should be able to do this with the matchit plugin by typing % when your mouse is on the opening tag.

    http://www.vim.org/scripts/script.php?script_id=39

    0 讨论(0)
提交回复
热议问题