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