xml.vim 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. " Vim filetype plugin file
  2. " Language: xml
  3. " Maintainer: Christian Brabandt <cb@256bit.org>
  4. " Last Changed: Dec 07th, 2018
  5. " 2024 Jan 14 by Vim Project (browsefilter)
  6. " 2024 May 23 by Riley Bruins <ribru17@gmail.com> ('commentstring')
  7. " Repository: https://github.com/chrisbra/vim-xml-ftplugin
  8. " Previous Maintainer: Dan Sharp
  9. " URL: http://dwsharp.users.sourceforge.net/vim/ftplugin
  10. if exists("b:did_ftplugin") | finish | endif
  11. let b:did_ftplugin = 1
  12. " Make sure the continuation lines below do not cause problems in
  13. " compatibility mode.
  14. let s:save_cpo = &cpo
  15. set cpo&vim
  16. setlocal commentstring=<!--\ %s\ -->
  17. " Remove the middlepart from the comments section, as this causes problems:
  18. " https://groups.google.com/d/msg/vim_dev/x4GT-nqa0Kg/jvtRnEbtAnMJ
  19. setlocal comments=s:<!--,e:-->
  20. setlocal formatoptions-=t
  21. setlocal formatoptions+=croql
  22. setlocal formatexpr=xmlformat#Format()
  23. " XML: thanks to Johannes Zellner and Akbar Ibrahim
  24. " - case sensitive
  25. " - don't match empty tags <fred/>
  26. " - match <!--, --> style comments (but not --, --)
  27. " - match <!, > inlined dtd's. This is not perfect, as it
  28. " gets confused for example by
  29. " <!ENTITY gt ">">
  30. if exists("loaded_matchit")
  31. let b:match_ignorecase=0
  32. let b:match_words =
  33. \ '<:>,' .
  34. \ '<\@<=!\[CDATA\[:]]>,'.
  35. \ '<\@<=!--:-->,'.
  36. \ '<\@<=?\k\+:?>,'.
  37. \ '<\@<=\([^ \t>/]\+\)\%(\s\+[^>]*\%([^/]>\|$\)\|>\|$\):<\@<=/\1>,'.
  38. \ '<\@<=\%([^ \t>/]\+\)\%(\s\+[^/>]*\|$\):/>'
  39. endif
  40. " For Omni completion, by Mikolaj Machowski.
  41. if exists('&ofu')
  42. setlocal ofu=xmlcomplete#CompleteTags
  43. endif
  44. command! -nargs=+ XMLns call xmlcomplete#CreateConnection(<f-args>)
  45. command! -nargs=? XMLent call xmlcomplete#CreateEntConnection(<f-args>)
  46. " Change the :browse e filter to primarily show xml-related files.
  47. if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
  48. let b:browsefilter="XML Files (*.xml)\t*.xml\n" .
  49. \ "DTD Files (*.dtd)\t*.dtd\n" .
  50. \ "XSD Files (*.xsd)\t*.xsd\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
  56. endif
  57. " Undo the stuff we changed.
  58. let b:undo_ftplugin = "setlocal commentstring< comments< formatoptions< formatexpr< " .
  59. \ " | unlet! b:match_ignorecase b:match_words b:browsefilter"
  60. " Restore the saved compatibility options.
  61. let &cpo = s:save_cpo
  62. unlet s:save_cpo