blob: 3627089ec251ffbc2d48fb3b8f440d4edf150db9 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim filetype plugin file
2" Language: C
3" Maintainer: Bram Moolenaar <Bram@vim.org>
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01004" Last Change: 2022 Apr 08
Bram Moolenaar071d4272004-06-13 20:20:40 +00005
6" Only do this when not done yet for this buffer
7if exists("b:did_ftplugin")
8 finish
9endif
10
11" Don't load another plugin for this buffer
12let b:did_ftplugin = 1
13
Bram Moolenaar582fd852005-03-28 20:58:01 +000014" Using line continuation here.
Bram Moolenaar30abd282005-06-22 22:35:10 +000015let s:cpo_save = &cpo
Bram Moolenaar071d4272004-06-13 20:20:40 +000016set cpo-=C
17
Bram Moolenaar560979e2020-02-04 22:53:05 +010018let b:undo_ftplugin = "setl fo< com< ofu< cms< def< inc< | if has('vms') | setl isk< | endif"
Bram Moolenaar071d4272004-06-13 20:20:40 +000019
20" Set 'formatoptions' to break comment lines but not other lines,
21" and insert the comment leader when hitting <CR> or using "o".
22setlocal fo-=t fo+=croql
23
Bram Moolenaar560979e2020-02-04 22:53:05 +010024" These options have the right value as default, but the user may have
25" overruled that.
26setlocal commentstring& define& include&
27
Bram Moolenaare344bea2005-09-01 20:46:49 +000028" Set completion with CTRL-X CTRL-O to autoloaded function.
29if exists('&ofu')
30 setlocal ofu=ccomplete#Complete
31endif
32
Bram Moolenaar071d4272004-06-13 20:20:40 +000033" Set 'comments' to format dashed lists in comments.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010034" Also include ///, used for Doxygen.
35setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,:///,://
Bram Moolenaar071d4272004-06-13 20:20:40 +000036
37" In VMS C keywords contain '$' characters.
38if has("vms")
39 setlocal iskeyword+=$
40endif
41
Bram Moolenaar446cb832008-06-24 21:56:24 +000042" When the matchit plugin is loaded, this makes the % command skip parens and
Bram Moolenaar01164a62017-11-02 22:58:42 +010043" braces in comments properly.
Bram Moolenaar34cc7d82021-09-21 20:09:51 +020044if !exists("b:match_words")
45 let b:match_words = '^\s*#\s*if\(\|def\|ndef\)\>:^\s*#\s*elif\>:^\s*#\s*else\>:^\s*#\s*endif\>'
46 let b:match_skip = 's:comment\|string\|character\|special'
47 let b:undo_ftplugin ..= " | unlet! b:match_skip b:match_words"
48endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000049
Bram Moolenaar071d4272004-06-13 20:20:40 +000050" Win32 can filter files in the browse dialog
Bram Moolenaar30b65812012-07-12 22:01:11 +020051if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
Bram Moolenaar071d4272004-06-13 20:20:40 +000052 if &ft == "cpp"
53 let b:browsefilter = "C++ Source Files (*.cpp *.c++)\t*.cpp;*.c++\n" .
54 \ "C Header Files (*.h)\t*.h\n" .
55 \ "C Source Files (*.c)\t*.c\n" .
56 \ "All Files (*.*)\t*.*\n"
Bram Moolenaard4755bb2004-09-02 19:12:26 +000057 elseif &ft == "ch"
Bram Moolenaar071d4272004-06-13 20:20:40 +000058 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" .
61 \ "All Files (*.*)\t*.*\n"
62 else
63 let b:browsefilter = "C Source Files (*.c)\t*.c\n" .
64 \ "C Header Files (*.h)\t*.h\n" .
65 \ "Ch Source Files (*.ch *.chf)\t*.ch;*.chf\n" .
66 \ "C++ Source Files (*.cpp *.c++)\t*.cpp;*.c++\n" .
67 \ "All Files (*.*)\t*.*\n"
68 endif
Bram Moolenaar34cc7d82021-09-21 20:09:51 +020069 let b:undo_ftplugin ..= " | unlet! b:browsefilter"
Bram Moolenaar071d4272004-06-13 20:20:40 +000070endif
Bram Moolenaar30abd282005-06-22 22:35:10 +000071
72let &cpo = s:cpo_save
73unlet s:cpo_save