html.vim (3246B)
1 " Vim filetype plugin file 2 " Language: HTML 3 " Maintainer: Doug Kearns <dougkearns@gmail.com> 4 " Previous Maintainer: Dan Sharp 5 " Last Change: 2025 Sep 12 6 " 2026 May 25 by Vim plugin: improve the matchit plugin #20313 7 8 if exists("b:did_ftplugin") 9 finish 10 endif 11 let b:did_ftplugin = 1 12 13 let s:save_cpo = &cpo 14 set cpo-=C 15 16 setlocal matchpairs+=<:> 17 setlocal commentstring=<!--\ %s\ --> 18 setlocal comments=s:<!--,m:\ \ \ \ ,e:--> 19 20 if exists('b:undo_ftplugin') 21 " no whitespace before |, handle possible :unmap at end of current value 22 let b:undo_ftplugin ..= "| setlocal comments< commentstring< matchpairs<" 23 else 24 let b:undo_ftplugin = "setlocal comments< commentstring< matchpairs<" 25 endif 26 27 if get(g:, "ft_html_autocomment", 0) 28 setlocal formatoptions-=t formatoptions+=croql 29 let b:undo_ftplugin ..= " | setlocal formatoptions<" 30 endif 31 32 if exists('&omnifunc') 33 setlocal omnifunc=htmlcomplete#CompleteTags 34 call htmlcomplete#DetectOmniFlavor() 35 let b:undo_ftplugin ..= " | setlocal omnifunc<" 36 endif 37 38 " HTML: thanks to Johannes Zellner and Benji Fisher. 39 if exists("loaded_matchit") && !exists("b:match_words") 40 let b:match_ignorecase = 1 41 let b:match_words = '<!--:-->,' .. 42 \ '<:>,' .. 43 \ '<\@<=[ou]l\>[^>]*\%(>\|$\):<\@<=li\>:<\@<=/[ou]l>,' .. 44 \ '<\@<=dl\>[^>]*\%(>\|$\):<\@<=d[td]\>:<\@<=/dl>,' .. 45 \ '<\@<=\([^/!][^ \t>]*\)\%([ \t]\|>\|$\):<\@<=/\1>' 46 let b:html_set_match_words = 1 47 let b:undo_ftplugin ..= " | unlet! b:match_ignorecase b:match_words b:html_set_match_words" 48 endif 49 50 " Change the :browse e filter to primarily show HTML-related files. 51 if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter") 52 let b:browsefilter = "HTML Files (*.html, *.htm)\t*.html;*.htm\n" .. 53 \ "JavaScript Files (*.js)\t*.js\n" .. 54 \ "Cascading StyleSheets (*.css)\t*.css\n" 55 if has("win32") 56 let b:browsefilter ..= "All Files (*.*)\t*\n" 57 else 58 let b:browsefilter ..= "All Files (*)\t*\n" 59 endif 60 let b:html_set_browsefilter = 1 61 let b:undo_ftplugin ..= " | unlet! b:browsefilter b:html_set_browsefilter" 62 endif 63 64 if has("folding") && get(g:, "html_expr_folding", 0) 65 function! HTMLTagFold() abort 66 if empty(get(b:, "foldsmap", {})) 67 if empty(get(b:, "current_syntax", '')) 68 return '0' 69 else 70 let b:foldsmap = htmlfold#MapBalancedTags() 71 endif 72 endif 73 74 return get(b:foldsmap, v:lnum, '=') 75 endfunction 76 77 setlocal foldexpr=HTMLTagFold() 78 setlocal foldmethod=expr 79 let b:undo_ftplugin ..= " | setlocal foldexpr< foldmethod<" 80 81 if !get(g:, "html_expr_folding_without_recomputation", 0) 82 augroup htmltagfold 83 autocmd! htmltagfold 84 autocmd TextChanged,InsertLeave <buffer> let b:foldsmap = {} 85 augroup END 86 87 " XXX: Keep ":autocmd" last in "b:undo_ftplugin" (see ":help :bar"). 88 let b:undo_ftplugin ..= " | silent! autocmd! htmltagfold * <buffer>" 89 endif 90 endif 91 92 let &cpo = s:save_cpo 93 unlet s:save_cpo 94 95 " See ":help vim9-mix". 96 if !has("vim9script") 97 finish 98 endif 99 100 if exists("*g:HTMLTagFold") 101 def! g:HTMLTagFold(): string 102 if empty(get(b:, "foldsmap", {})) 103 if empty(get(b:, "current_syntax", '')) 104 return '0' 105 else 106 b:foldsmap = g:htmlfold#MapBalancedTags() 107 endif 108 endif 109 110 return get(b:foldsmap, v:lnum, '=') 111 enddef 112 endif