blob: 645f8c3e67f7fa4a31213d35fb706e57e6a85e48 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim support file to switch on loading plugins for file types
2"
3" Maintainer: Bram Moolenaar <Bram@vim.org>
Bram Moolenaar3e79c972022-02-04 19:48:06 +00004" Last change: 2022 Feb 04
Bram Moolenaar071d4272004-06-13 20:20:40 +00005
6if exists("did_load_ftplugin")
7 finish
8endif
9let did_load_ftplugin = 1
10
11augroup filetypeplugin
12 au FileType * call s:LoadFTPlugin()
Bram Moolenaar071d4272004-06-13 20:20:40 +000013augroup END
Bram Moolenaar3e79c972022-02-04 19:48:06 +000014
15def s:LoadFTPlugin()
16 if exists("b:undo_ftplugin")
17 exe b:undo_ftplugin
18 unlet! b:undo_ftplugin b:did_ftplugin
19 endif
20
21 var s = expand("<amatch>")
22 if s != ""
23 if &cpo =~# "S" && exists("b:did_ftplugin")
24 # In compatible mode options are reset to the global values, need to
25 # set the local values also when a plugin was already used.
26 unlet b:did_ftplugin
27 endif
28
29 # When there is a dot it is used to separate filetype names. Thus for
30 # "aaa.bbb" load "aaa" and then "bbb".
31 for name in split(s, '\.')
32 exe 'runtime! ftplugin/' .. name .. '.vim ftplugin/' .. name .. '_*.vim ftplugin/' .. name .. '/*.vim'
33 endfor
34 endif
35enddef