c.vim 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. " Vim filetype plugin file
  2. " Language: C
  3. " Maintainer: Bram Moolenaar <Bram@vim.org>
  4. " Last Change: 2022 Apr 08
  5. " Only do this when not done yet for this buffer
  6. if exists("b:did_ftplugin")
  7. finish
  8. endif
  9. " Don't load another plugin for this buffer
  10. let b:did_ftplugin = 1
  11. " Using line continuation here.
  12. let s:cpo_save = &cpo
  13. set cpo-=C
  14. let b:undo_ftplugin = "setl fo< com< ofu< cms< def< inc< | if has('vms') | setl isk< | endif"
  15. " Set 'formatoptions' to break comment lines but not other lines,
  16. " and insert the comment leader when hitting <CR> or using "o".
  17. setlocal fo-=t fo+=croql
  18. " These options have the right value as default, but the user may have
  19. " overruled that.
  20. setlocal commentstring& define& include&
  21. " Set completion with CTRL-X CTRL-O to autoloaded function.
  22. if exists('&ofu')
  23. setlocal ofu=ccomplete#Complete
  24. endif
  25. " Set 'comments' to format dashed lists in comments.
  26. " Also include ///, used for Doxygen.
  27. setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,:///,://
  28. " In VMS C keywords contain '$' characters.
  29. if has("vms")
  30. setlocal iskeyword+=$
  31. endif
  32. " When the matchit plugin is loaded, this makes the % command skip parens and
  33. " braces in comments properly.
  34. if !exists("b:match_words")
  35. let b:match_words = '^\s*#\s*if\(\|def\|ndef\)\>:^\s*#\s*elif\>:^\s*#\s*else\>:^\s*#\s*endif\>'
  36. let b:match_skip = 's:comment\|string\|character\|special'
  37. let b:undo_ftplugin ..= " | unlet! b:match_skip b:match_words"
  38. endif
  39. " Win32 can filter files in the browse dialog
  40. if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
  41. if &ft == "cpp"
  42. let b:browsefilter = "C++ Source Files (*.cpp *.c++)\t*.cpp;*.c++\n" .
  43. \ "C Header Files (*.h)\t*.h\n" .
  44. \ "C Source Files (*.c)\t*.c\n" .
  45. \ "All Files (*.*)\t*.*\n"
  46. elseif &ft == "ch"
  47. let b:browsefilter = "Ch Source Files (*.ch *.chf)\t*.ch;*.chf\n" .
  48. \ "C Header Files (*.h)\t*.h\n" .
  49. \ "C Source Files (*.c)\t*.c\n" .
  50. \ "All Files (*.*)\t*.*\n"
  51. else
  52. let b:browsefilter = "C Source Files (*.c)\t*.c\n" .
  53. \ "C Header Files (*.h)\t*.h\n" .
  54. \ "Ch Source Files (*.ch *.chf)\t*.ch;*.chf\n" .
  55. \ "C++ Source Files (*.cpp *.c++)\t*.cpp;*.c++\n" .
  56. \ "All Files (*.*)\t*.*\n"
  57. endif
  58. let b:undo_ftplugin ..= " | unlet! b:browsefilter"
  59. endif
  60. let &cpo = s:cpo_save
  61. unlet s:cpo_save