Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim filetype plugin file |
| 2 | " Language: C |
| 3 | " Maintainer: Bram Moolenaar <Bram@vim.org> |
Bram Moolenaar | 34cc7d8 | 2021-09-21 20:09:51 +0200 | [diff] [blame] | 4 | " Last Change: 2021 Sep 21 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5 | |
| 6 | " Only do this when not done yet for this buffer |
| 7 | if exists("b:did_ftplugin") |
| 8 | finish |
| 9 | endif |
| 10 | |
| 11 | " Don't load another plugin for this buffer |
| 12 | let b:did_ftplugin = 1 |
| 13 | |
Bram Moolenaar | 582fd85 | 2005-03-28 20:58:01 +0000 | [diff] [blame] | 14 | " Using line continuation here. |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 15 | let s:cpo_save = &cpo |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 16 | set cpo-=C |
| 17 | |
Bram Moolenaar | 560979e | 2020-02-04 22:53:05 +0100 | [diff] [blame] | 18 | 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] | 19 | |
| 20 | " Set 'formatoptions' to break comment lines but not other lines, |
| 21 | " and insert the comment leader when hitting <CR> or using "o". |
| 22 | setlocal fo-=t fo+=croql |
| 23 | |
Bram Moolenaar | 560979e | 2020-02-04 22:53:05 +0100 | [diff] [blame] | 24 | " These options have the right value as default, but the user may have |
| 25 | " overruled that. |
| 26 | setlocal commentstring& define& include& |
| 27 | |
Bram Moolenaar | e344bea | 2005-09-01 20:46:49 +0000 | [diff] [blame] | 28 | " Set completion with CTRL-X CTRL-O to autoloaded function. |
| 29 | if exists('&ofu') |
| 30 | setlocal ofu=ccomplete#Complete |
| 31 | endif |
| 32 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 33 | " Set 'comments' to format dashed lists in comments. |
| 34 | setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,:// |
| 35 | |
| 36 | " In VMS C keywords contain '$' characters. |
| 37 | if has("vms") |
| 38 | setlocal iskeyword+=$ |
| 39 | endif |
| 40 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 41 | " 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] | 42 | " braces in comments properly. |
Bram Moolenaar | 34cc7d8 | 2021-09-21 20:09:51 +0200 | [diff] [blame] | 43 | if !exists("b:match_words") |
| 44 | let b:match_words = '^\s*#\s*if\(\|def\|ndef\)\>:^\s*#\s*elif\>:^\s*#\s*else\>:^\s*#\s*endif\>' |
| 45 | let b:match_skip = 's:comment\|string\|character\|special' |
| 46 | let b:undo_ftplugin ..= " | unlet! b:match_skip b:match_words" |
| 47 | endif |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 48 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 49 | " Win32 can filter files in the browse dialog |
Bram Moolenaar | 30b6581 | 2012-07-12 22:01:11 +0200 | [diff] [blame] | 50 | if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 51 | if &ft == "cpp" |
| 52 | let b:browsefilter = "C++ Source Files (*.cpp *.c++)\t*.cpp;*.c++\n" . |
| 53 | \ "C Header Files (*.h)\t*.h\n" . |
| 54 | \ "C Source Files (*.c)\t*.c\n" . |
| 55 | \ "All Files (*.*)\t*.*\n" |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 56 | elseif &ft == "ch" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 57 | let b:browsefilter = "Ch Source Files (*.ch *.chf)\t*.ch;*.chf\n" . |
| 58 | \ "C Header Files (*.h)\t*.h\n" . |
| 59 | \ "C Source Files (*.c)\t*.c\n" . |
| 60 | \ "All Files (*.*)\t*.*\n" |
| 61 | else |
| 62 | 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 | \ "All Files (*.*)\t*.*\n" |
| 67 | endif |
Bram Moolenaar | 34cc7d8 | 2021-09-21 20:09:51 +0200 | [diff] [blame] | 68 | let b:undo_ftplugin ..= " | unlet! b:browsefilter" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 69 | endif |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 70 | |
| 71 | let &cpo = s:cpo_save |
| 72 | unlet s:cpo_save |