ftplugin.vim 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. " Vim support file to switch on loading plugins for file types
  2. "
  3. " Maintainer: The Vim Project <https://github.com/vim/vim>
  4. " Last change: 2023 Aug 10
  5. " Former Maintainer: Bram Moolenaar <Bram@vim.org>
  6. if exists("did_load_ftplugin")
  7. finish
  8. endif
  9. let did_load_ftplugin = 1
  10. augroup filetypeplugin
  11. au FileType * call s:LoadFTPlugin()
  12. func! s:LoadFTPlugin()
  13. if exists("b:undo_ftplugin")
  14. exe b:undo_ftplugin
  15. unlet! b:undo_ftplugin b:did_ftplugin
  16. endif
  17. let s = expand("<amatch>")
  18. if s != ""
  19. if &cpo =~# "S" && exists("b:did_ftplugin")
  20. " In compatible mode options are reset to the global values, need to
  21. " set the local values also when a plugin was already used.
  22. unlet b:did_ftplugin
  23. endif
  24. " When there is a dot it is used to separate filetype names. Thus for
  25. " "aaa.bbb" load "aaa" and then "bbb".
  26. for name in split(s, '\.')
  27. " Load Lua ftplugins after Vim ftplugins _per directory_
  28. " TODO(clason): use nvim__get_runtime when supports globs and modeline
  29. " XXX: "[.]" in the first pattern makes it a wildcard on Windows
  30. exe $'runtime! ftplugin/{name}[.]{{vim,lua}} ftplugin/{name}_*.{{vim,lua}} ftplugin/{name}/*.{{vim,lua}}'
  31. endfor
  32. endif
  33. endfunc
  34. augroup END