blob: 7736b5b05405026066a03dc31a1b76da96135a30 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim filetype plugin file
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01002" Language: HTML
3" Maintainer: Doug Kearns <dougkearns@gmail.com>
4" Previous Maintainer: Dan Sharp
Doug Kearns93197fd2024-01-14 20:59:02 +01005" Last Change: 2024 Jan 14
Aliaksei Budaveidc7ed8f2025-05-10 21:40:41 +02006" 2024 May 24 update 'commentstring' option
7" 2025 May 10 add expression folding #17141
Bram Moolenaar071d4272004-06-13 20:20:40 +00008
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01009if exists("b:did_ftplugin")
10 finish
11endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012let b:did_ftplugin = 1
13
Bram Moolenaar071d4272004-06-13 20:20:40 +000014let s:save_cpo = &cpo
15set cpo-=C
16
Bram Moolenaara7241f52008-06-24 20:39:31 +000017setlocal matchpairs+=<:>
Riley Bruins0a083062024-06-03 20:40:45 +020018setlocal commentstring=<!--\ %s\ -->
Bram Moolenaare37d50a2008-08-06 17:06:04 +000019setlocal comments=s:<!--,m:\ \ \ \ ,e:-->
20
Bram Moolenaarb529cfb2022-07-25 15:42:07 +010021let b:undo_ftplugin = "setlocal comments< commentstring< matchpairs<"
22
23if get(g:, "ft_html_autocomment", 0)
24 setlocal formatoptions-=t formatoptions+=croql
25 let b:undo_ftplugin ..= " | setlocal formatoptions<"
Bram Moolenaare37d50a2008-08-06 17:06:04 +000026endif
27
Bram Moolenaarf193fff2006-04-27 00:02:13 +000028if exists('&omnifunc')
Bram Moolenaar946e27a2014-06-25 18:50:27 +020029 setlocal omnifunc=htmlcomplete#CompleteTags
30 call htmlcomplete#DetectOmniFlavor()
Bram Moolenaarb529cfb2022-07-25 15:42:07 +010031 let b:undo_ftplugin ..= " | setlocal omnifunc<"
Bram Moolenaarf193fff2006-04-27 00:02:13 +000032endif
Bram Moolenaar4a85b412006-04-23 22:40:29 +000033
Bram Moolenaarb529cfb2022-07-25 15:42:07 +010034" HTML: thanks to Johannes Zellner and Benji Fisher.
35if exists("loaded_matchit") && !exists("b:match_words")
36 let b:match_ignorecase = 1
37 let b:match_words = '<!--:-->,' ..
38 \ '<:>,' ..
39 \ '<\@<=[ou]l\>[^>]*\%(>\|$\):<\@<=li\>:<\@<=/[ou]l>,' ..
40 \ '<\@<=dl\>[^>]*\%(>\|$\):<\@<=d[td]\>:<\@<=/dl>,' ..
41 \ '<\@<=\([^/!][^ \t>]*\)[^>]*\%(>\|$\):<\@<=/\1>'
42 let b:html_set_match_words = 1
43 let b:undo_ftplugin ..= " | unlet! b:match_ignorecase b:match_words b:html_set_match_words"
Bram Moolenaar071d4272004-06-13 20:20:40 +000044endif
45
46" Change the :browse e filter to primarily show HTML-related files.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +010047if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
Doug Kearns93197fd2024-01-14 20:59:02 +010048 let b:browsefilter = "HTML Files (*.html, *.htm)\t*.html;*.htm\n" ..
Bram Moolenaarb529cfb2022-07-25 15:42:07 +010049 \ "JavaScript Files (*.js)\t*.js\n" ..
Doug Kearns93197fd2024-01-14 20:59:02 +010050 \ "Cascading StyleSheets (*.css)\t*.css\n"
51 if has("win32")
52 let b:browsefilter ..= "All Files (*.*)\t*\n"
53 else
54 let b:browsefilter ..= "All Files (*)\t*\n"
55 endif
Bram Moolenaarb529cfb2022-07-25 15:42:07 +010056 let b:html_set_browsefilter = 1
57 let b:undo_ftplugin ..= " | unlet! b:browsefilter b:html_set_browsefilter"
Bram Moolenaar071d4272004-06-13 20:20:40 +000058endif
59
Aliaksei Budaveidc7ed8f2025-05-10 21:40:41 +020060if has("folding") && get(g:, "html_expr_folding", 0)
61 function! HTMLTagFold() abort
62 if empty(get(b:, "foldsmap", {}))
63 if empty(get(b:, "current_syntax", ''))
64 return '0'
65 else
66 let b:foldsmap = htmlfold#MapBalancedTags()
67 endif
68 endif
69
70 return get(b:foldsmap, v:lnum, '=')
71 endfunction
72
73 setlocal foldexpr=HTMLTagFold()
74 setlocal foldmethod=expr
75 let b:undo_ftplugin ..= " | setlocal foldexpr< foldmethod<"
76
77 if !get(g:, "html_expr_folding_without_recomputation", 0)
78 augroup htmltagfold
79 autocmd! htmltagfold
80 autocmd TextChanged,InsertLeave <buffer> let b:foldsmap = {}
81 augroup END
82
83 " XXX: Keep ":autocmd" last in "b:undo_ftplugin" (see ":help :bar").
84 let b:undo_ftplugin ..= " | silent! autocmd! htmltagfold * <buffer>"
85 endif
86endif
87
Bram Moolenaar071d4272004-06-13 20:20:40 +000088let &cpo = s:save_cpo
Bram Moolenaar84f72352012-03-11 15:57:40 +010089unlet s:save_cpo
Aliaksei Budaveidc7ed8f2025-05-10 21:40:41 +020090
91" See ":help vim9-mix".
92if !has("vim9script")
93 finish
94endif
95
96if exists("*g:HTMLTagFold")
97 def! g:HTMLTagFold(): string
98 if empty(get(b:, "foldsmap", {}))
99 if empty(get(b:, "current_syntax", ''))
100 return '0'
101 else
102 b:foldsmap = g:htmlfold#MapBalancedTags()
103 endif
104 endif
105
106 return get(b:foldsmap, v:lnum, '=')
107 enddef
108endif