Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim filetype plugin file |
| 2 | " Language: C |
Christian Brabandt | e978b45 | 2023-08-13 10:33:05 +0200 | [diff] [blame] | 3 | " Maintainer: The Vim Project <https://github.com/vim/vim> |
Doug Kearns | 93197fd | 2024-01-14 20:59:02 +0100 | [diff] [blame] | 4 | " Last Change: 2023 Aug 22 |
Riley Bruins | 0a08306 | 2024-06-03 20:40:45 +0200 | [diff] [blame] | 5 | " 2024 Jun 02 by Riley Bruins <ribru17@gmail.com> ('commentstring') |
Christian Brabandt | e978b45 | 2023-08-13 10:33:05 +0200 | [diff] [blame] | 6 | " Former Maintainer: Bram Moolenaar <Bram@vim.org> |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7 | |
| 8 | " Only do this when not done yet for this buffer |
| 9 | if exists("b:did_ftplugin") |
| 10 | finish |
| 11 | endif |
| 12 | |
| 13 | " Don't load another plugin for this buffer |
| 14 | let b:did_ftplugin = 1 |
| 15 | |
Bram Moolenaar | 582fd85 | 2005-03-28 20:58:01 +0000 | [diff] [blame] | 16 | " Using line continuation here. |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 17 | let s:cpo_save = &cpo |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 18 | set cpo-=C |
| 19 | |
Bram Moolenaar | 560979e | 2020-02-04 22:53:05 +0100 | [diff] [blame] | 20 | let b:undo_ftplugin = "setl fo< com< ofu< cms< def< inc< | if has('vms') | setl isk< | endif" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 21 | |
| 22 | " Set 'formatoptions' to break comment lines but not other lines, |
| 23 | " and insert the comment leader when hitting <CR> or using "o". |
| 24 | setlocal fo-=t fo+=croql |
| 25 | |
Bram Moolenaar | 560979e | 2020-02-04 22:53:05 +0100 | [diff] [blame] | 26 | " These options have the right value as default, but the user may have |
| 27 | " overruled that. |
Riley Bruins | 0a08306 | 2024-06-03 20:40:45 +0200 | [diff] [blame] | 28 | setlocal commentstring=/*\ %s\ */ define& include& |
Bram Moolenaar | 560979e | 2020-02-04 22:53:05 +0100 | [diff] [blame] | 29 | |
Bram Moolenaar | e344bea | 2005-09-01 20:46:49 +0000 | [diff] [blame] | 30 | " Set completion with CTRL-X CTRL-O to autoloaded function. |
| 31 | if exists('&ofu') |
| 32 | setlocal ofu=ccomplete#Complete |
| 33 | endif |
| 34 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 35 | " Set 'comments' to format dashed lists in comments. |
Bram Moolenaar | cbaff5e | 2022-04-08 17:45:08 +0100 | [diff] [blame] | 36 | " Also include ///, used for Doxygen. |
| 37 | setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,:///,:// |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 38 | |
| 39 | " In VMS C keywords contain '$' characters. |
| 40 | if has("vms") |
| 41 | setlocal iskeyword+=$ |
| 42 | endif |
| 43 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 44 | " When the matchit plugin is loaded, this makes the % command skip parens and |
Bram Moolenaar | 01164a6 | 2017-11-02 22:58:42 +0100 | [diff] [blame] | 45 | " braces in comments properly. |
Bram Moolenaar | 34cc7d8 | 2021-09-21 20:09:51 +0200 | [diff] [blame] | 46 | if !exists("b:match_words") |
Doug Kearns | c2a967a | 2025-01-17 14:12:16 +0100 | [diff] [blame] | 47 | let b:match_words = '^\s*#\s*if\%(\|def\|ndef\)\>:^\s*#\s*elif\%(\|def\|ndef\)\>:^\s*#\s*else\>:^\s*#\s*endif\>' |
Bram Moolenaar | 34cc7d8 | 2021-09-21 20:09:51 +0200 | [diff] [blame] | 48 | let b:match_skip = 's:comment\|string\|character\|special' |
| 49 | let b:undo_ftplugin ..= " | unlet! b:match_skip b:match_words" |
| 50 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 51 | |
Doug Kearns | 93197fd | 2024-01-14 20:59:02 +0100 | [diff] [blame] | 52 | " Win32 and GTK can filter files in the browse dialog |
Bram Moolenaar | 30b6581 | 2012-07-12 22:01:11 +0200 | [diff] [blame] | 53 | if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 54 | if &ft == "cpp" |
Doug Kearns | 93197fd | 2024-01-14 20:59:02 +0100 | [diff] [blame] | 55 | 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 Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 58 | elseif &ft == "ch" |
Doug Kearns | 93197fd | 2024-01-14 20:59:02 +0100 | [diff] [blame] | 59 | 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 Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 62 | else |
Doug Kearns | 93197fd | 2024-01-14 20:59:02 +0100 | [diff] [blame] | 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 | endif |
| 68 | if has("win32") |
| 69 | let b:browsefilter ..= "All Files (*.*)\t*\n" |
| 70 | else |
| 71 | let b:browsefilter ..= "All Files (*)\t*\n" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 72 | endif |
Bram Moolenaar | 34cc7d8 | 2021-09-21 20:09:51 +0200 | [diff] [blame] | 73 | let b:undo_ftplugin ..= " | unlet! b:browsefilter" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 74 | endif |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 75 | |
| 76 | let &cpo = s:cpo_save |
| 77 | unlet s:cpo_save |