ftplugin.vim (1200B)
1 vim9script noclear 2 3 # Vim support file to switch on loading plugins for file types 4 # 5 # Maintainer: The Vim Project <https://github.com/vim/vim> 6 # Last change: 2023 Aug 10 7 # Former Maintainer: Bram Moolenaar <Bram@vim.org> 8 9 if exists("g:did_load_ftplugin") 10 finish 11 endif 12 g:did_load_ftplugin = 1 13 14 augroup filetypeplugin 15 au FileType * call LoadFTPlugin() 16 augroup END 17 18 if exists('*LoadFTPlugin') 19 # No need to define the function again. 20 finish 21 endif 22 23 def LoadFTPlugin() 24 if exists("b:undo_ftplugin") 25 # We assume b:undo_ftplugin is using legacy script syntax 26 legacy exe b:undo_ftplugin 27 unlet! b:undo_ftplugin b:did_ftplugin 28 endif 29 30 var s = expand("<amatch>") 31 if s != "" 32 if &cpo =~# "S" && exists("b:did_ftplugin") 33 # In compatible mode options are reset to the global values, need to 34 # set the local values also when a plugin was already used. 35 unlet b:did_ftplugin 36 endif 37 38 # When there is a dot it is used to separate filetype names. Thus for 39 # "aaa.bbb" load "aaa" and then "bbb". 40 for name in split(s, '\.') 41 exe 'runtime! ftplugin/' .. name .. '.vim ftplugin/' .. name .. '_*.vim ftplugin/' .. name .. '/*.vim' 42 endfor 43 endif 44 enddef