blob: e2eebc5492a8f7291592f6535d199f3cecc40dfa [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim filetype plugin file
2" Language: C
Christian Brabandte978b452023-08-13 10:33:05 +02003" Maintainer: The Vim Project <https://github.com/vim/vim>
Doug Kearns93197fd2024-01-14 20:59:02 +01004" Last Change: 2023 Aug 22
Christian Brabandte978b452023-08-13 10:33:05 +02005" Former Maintainer: Bram Moolenaar <Bram@vim.org>
Bram Moolenaar071d4272004-06-13 20:20:40 +00006
7" Only do this when not done yet for this buffer
8if exists("b:did_ftplugin")
9 finish
10endif
11
12" Don't load another plugin for this buffer
13let b:did_ftplugin = 1
14
Bram Moolenaar582fd852005-03-28 20:58:01 +000015" Using line continuation here.
Bram Moolenaar30abd282005-06-22 22:35:10 +000016let s:cpo_save = &cpo
Bram Moolenaar071d4272004-06-13 20:20:40 +000017set cpo-=C
18
Bram Moolenaar560979e2020-02-04 22:53:05 +010019let b:undo_ftplugin = "setl fo< com< ofu< cms< def< inc< | if has('vms') | setl isk< | endif"
Bram Moolenaar071d4272004-06-13 20:20:40 +000020
21" Set 'formatoptions' to break comment lines but not other lines,
22" and insert the comment leader when hitting <CR> or using "o".
23setlocal fo-=t fo+=croql
24
Bram Moolenaar560979e2020-02-04 22:53:05 +010025" These options have the right value as default, but the user may have
26" overruled that.
27setlocal commentstring& define& include&
28
Bram Moolenaare344bea2005-09-01 20:46:49 +000029" Set completion with CTRL-X CTRL-O to autoloaded function.
30if exists('&ofu')
31 setlocal ofu=ccomplete#Complete
32endif
33
Bram Moolenaar071d4272004-06-13 20:20:40 +000034" Set 'comments' to format dashed lists in comments.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010035" Also include ///, used for Doxygen.
36setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,:///,://
Bram Moolenaar071d4272004-06-13 20:20:40 +000037
38" In VMS C keywords contain '$' characters.
39if has("vms")
40 setlocal iskeyword+=$
41endif
42
Bram Moolenaar446cb832008-06-24 21:56:24 +000043" When the matchit plugin is loaded, this makes the % command skip parens and
Bram Moolenaar01164a62017-11-02 22:58:42 +010044" braces in comments properly.
Bram Moolenaar34cc7d82021-09-21 20:09:51 +020045if !exists("b:match_words")
46 let b:match_words = '^\s*#\s*if\(\|def\|ndef\)\>:^\s*#\s*elif\>:^\s*#\s*else\>:^\s*#\s*endif\>'
47 let b:match_skip = 's:comment\|string\|character\|special'
48 let b:undo_ftplugin ..= " | unlet! b:match_skip b:match_words"
49endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000050
Doug Kearns93197fd2024-01-14 20:59:02 +010051" Win32 and GTK can filter files in the browse dialog
Bram Moolenaar30b65812012-07-12 22:01:11 +020052if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
Bram Moolenaar071d4272004-06-13 20:20:40 +000053 if &ft == "cpp"
Doug Kearns93197fd2024-01-14 20:59:02 +010054 let b:browsefilter = "C++ Source Files (*.cpp, *.c++)\t*.cpp;*.c++\n" ..
55 \ "C Header Files (*.h)\t*.h\n" ..
56 \ "C Source Files (*.c)\t*.c\n"
Bram Moolenaard4755bb2004-09-02 19:12:26 +000057 elseif &ft == "ch"
Doug Kearns93197fd2024-01-14 20:59:02 +010058 let b:browsefilter = "Ch Source Files (*.ch, *.chf)\t*.ch;*.chf\n" ..
59 \ "C Header Files (*.h)\t*.h\n" ..
60 \ "C Source Files (*.c)\t*.c\n"
Bram Moolenaar071d4272004-06-13 20:20:40 +000061 else
Doug Kearns93197fd2024-01-14 20:59:02 +010062 let b:browsefilter = "C Source Files (*.c)\t*.c\n" ..
63 \ "C Header Files (*.h)\t*.h\n" ..
64 \ "Ch Source Files (*.ch, *.chf)\t*.ch;*.chf\n" ..
65 \ "C++ Source Files (*.cpp, *.c++)\t*.cpp;*.c++\n"
66 endif
67 if has("win32")
68 let b:browsefilter ..= "All Files (*.*)\t*\n"
69 else
70 let b:browsefilter ..= "All Files (*)\t*\n"
Bram Moolenaar071d4272004-06-13 20:20:40 +000071 endif
Bram Moolenaar34cc7d82021-09-21 20:09:51 +020072 let b:undo_ftplugin ..= " | unlet! b:browsefilter"
Bram Moolenaar071d4272004-06-13 20:20:40 +000073endif
Bram Moolenaar30abd282005-06-22 22:35:10 +000074
75let &cpo = s:cpo_save
76unlet s:cpo_save