blob: 915861b8d50a72d3ebd4fce74158c5676c1e980d [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
Riley Bruins0a083062024-06-03 20:40:45 +02005" 2024 Jun 02 by Riley Bruins <ribru17@gmail.com> ('commentstring')
Christian Brabandte978b452023-08-13 10:33:05 +02006" Former Maintainer: Bram Moolenaar <Bram@vim.org>
Bram Moolenaar071d4272004-06-13 20:20:40 +00007
8" Only do this when not done yet for this buffer
9if exists("b:did_ftplugin")
10 finish
11endif
12
13" Don't load another plugin for this buffer
14let b:did_ftplugin = 1
15
Bram Moolenaar582fd852005-03-28 20:58:01 +000016" Using line continuation here.
Bram Moolenaar30abd282005-06-22 22:35:10 +000017let s:cpo_save = &cpo
Bram Moolenaar071d4272004-06-13 20:20:40 +000018set cpo-=C
19
Bram Moolenaar560979e2020-02-04 22:53:05 +010020let b:undo_ftplugin = "setl fo< com< ofu< cms< def< inc< | if has('vms') | setl isk< | endif"
Bram Moolenaar071d4272004-06-13 20:20:40 +000021
22" Set 'formatoptions' to break comment lines but not other lines,
23" and insert the comment leader when hitting <CR> or using "o".
24setlocal fo-=t fo+=croql
25
Bram Moolenaar560979e2020-02-04 22:53:05 +010026" These options have the right value as default, but the user may have
27" overruled that.
Riley Bruins0a083062024-06-03 20:40:45 +020028setlocal commentstring=/*\ %s\ */ define& include&
Bram Moolenaar560979e2020-02-04 22:53:05 +010029
Bram Moolenaare344bea2005-09-01 20:46:49 +000030" Set completion with CTRL-X CTRL-O to autoloaded function.
31if exists('&ofu')
32 setlocal ofu=ccomplete#Complete
33endif
34
Bram Moolenaar071d4272004-06-13 20:20:40 +000035" Set 'comments' to format dashed lists in comments.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010036" Also include ///, used for Doxygen.
37setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,:///,://
Bram Moolenaar071d4272004-06-13 20:20:40 +000038
39" In VMS C keywords contain '$' characters.
40if has("vms")
41 setlocal iskeyword+=$
42endif
43
Bram Moolenaar446cb832008-06-24 21:56:24 +000044" When the matchit plugin is loaded, this makes the % command skip parens and
Bram Moolenaar01164a62017-11-02 22:58:42 +010045" braces in comments properly.
Bram Moolenaar34cc7d82021-09-21 20:09:51 +020046if !exists("b:match_words")
Doug Kearnsc2a967a2025-01-17 14:12:16 +010047 let b:match_words = '^\s*#\s*if\%(\|def\|ndef\)\>:^\s*#\s*elif\%(\|def\|ndef\)\>:^\s*#\s*else\>:^\s*#\s*endif\>'
Bram Moolenaar34cc7d82021-09-21 20:09:51 +020048 let b:match_skip = 's:comment\|string\|character\|special'
49 let b:undo_ftplugin ..= " | unlet! b:match_skip b:match_words"
50endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000051
Doug Kearns93197fd2024-01-14 20:59:02 +010052" Win32 and GTK can filter files in the browse dialog
Bram Moolenaar30b65812012-07-12 22:01:11 +020053if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
Bram Moolenaar071d4272004-06-13 20:20:40 +000054 if &ft == "cpp"
Doug Kearns93197fd2024-01-14 20:59:02 +010055 let b:browsefilter = "C++ Source Files (*.cpp, *.c++)\t*.cpp;*.c++\n" ..
56 \ "C Header Files (*.h)\t*.h\n" ..
57 \ "C Source Files (*.c)\t*.c\n"
Bram Moolenaard4755bb2004-09-02 19:12:26 +000058 elseif &ft == "ch"
Doug Kearns93197fd2024-01-14 20:59:02 +010059 let b:browsefilter = "Ch Source Files (*.ch, *.chf)\t*.ch;*.chf\n" ..
60 \ "C Header Files (*.h)\t*.h\n" ..
61 \ "C Source Files (*.c)\t*.c\n"
Bram Moolenaar071d4272004-06-13 20:20:40 +000062 else
Doug Kearns93197fd2024-01-14 20:59:02 +010063 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 endif
68 if has("win32")
69 let b:browsefilter ..= "All Files (*.*)\t*\n"
70 else
71 let b:browsefilter ..= "All Files (*)\t*\n"
Bram Moolenaar071d4272004-06-13 20:20:40 +000072 endif
Bram Moolenaar34cc7d82021-09-21 20:09:51 +020073 let b:undo_ftplugin ..= " | unlet! b:browsefilter"
Bram Moolenaar071d4272004-06-13 20:20:40 +000074endif
Bram Moolenaar30abd282005-06-22 22:35:10 +000075
76let &cpo = s:cpo_save
77unlet s:cpo_save