c.vim (3009B)
1 " Vim filetype plugin file 2 " Language: C 3 " Maintainer: The Vim Project <https://github.com/vim/vim> 4 " Last Change: 2026 Oct 12 5 " Former Maintainer: Bram Moolenaar <Bram@vim.org> 6 7 " Only do this when not done yet for this buffer 8 if exists("b:did_ftplugin") 9 finish 10 endif 11 12 " Don't load another plugin for this buffer 13 let b:did_ftplugin = 1 14 15 " Using line continuation here. 16 let s:cpo_save = &cpo 17 set cpo-=C 18 19 let b:undo_ftplugin = "setl fo< com< ofu< cms< def< inc< | if has('vms') | setl isk< | endif" 20 21 " Set 'formatoptions' to break comment lines but not other lines, 22 " and insert the comment leader when hitting <CR> or using "o". 23 setlocal fo-=t fo+=croql 24 25 " These options have the right value as default, but the user may have 26 " overruled that. 27 setlocal commentstring=/*\ %s\ */ define& include& 28 29 " Set completion with CTRL-X CTRL-O to autoloaded function. 30 if exists('&ofu') && has("vim9script") 31 setlocal ofu=ccomplete#Complete 32 endif 33 34 " Set 'comments' to format dashed lists in comments. 35 " Also include ///, used for Doxygen. 36 setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,:///,:// 37 38 " In VMS C keywords contain '$' characters. 39 if has("vms") 40 setlocal iskeyword+=$ 41 endif 42 43 " Use terminal window for gui 44 if has('gui_running') && has('terminal') && executable("man") 45 setlocal keywordprg=:CKeywordPrg 46 47 command! -buffer -nargs=1 -count CKeywordPrg call s:CKeywordPrg(<q-args>, <count>) 48 49 function! s:CKeywordPrg(arg, count) abort 50 let arg = escape(a:arg, '\%#') 51 if a:count > 0 52 exe printf('term ++close man -s %d %s', a:count, arg) 53 else 54 exe printf('term ++close man %s', arg) 55 endif 56 endfunction 57 58 let b:undo_ftplugin .= ' | setl kp< | sil! delc -buffer CKeywordPrg' 59 endif 60 61 " When the matchit plugin is loaded, this makes the % command skip parens and 62 " braces in comments properly. 63 if !exists("b:match_words") 64 let b:match_words = '^\s*#\s*if\%(\|def\|ndef\)\>:^\s*#\s*elif\%(\|def\|ndef\)\>:^\s*#\s*else\>:^\s*#\s*endif\>' 65 let b:match_skip = 's:comment\|string\|character\|special' 66 let b:undo_ftplugin ..= " | unlet! b:match_skip b:match_words" 67 endif 68 69 " Win32 and GTK can filter files in the browse dialog 70 if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter") 71 if &ft == "cpp" 72 let b:browsefilter = "C++ Source Files (*.cpp, *.c++)\t*.cpp;*.c++\n" .. 73 \ "C Header Files (*.h)\t*.h\n" .. 74 \ "C Source Files (*.c)\t*.c\n" 75 elseif &ft == "ch" 76 let b:browsefilter = "Ch Source Files (*.ch, *.chf)\t*.ch;*.chf\n" .. 77 \ "C Header Files (*.h)\t*.h\n" .. 78 \ "C Source Files (*.c)\t*.c\n" 79 else 80 let b:browsefilter = "C Source Files (*.c)\t*.c\n" .. 81 \ "C Header Files (*.h)\t*.h\n" .. 82 \ "Ch Source Files (*.ch, *.chf)\t*.ch;*.chf\n" .. 83 \ "C++ Source Files (*.cpp, *.c++)\t*.cpp;*.c++\n" 84 endif 85 if has("win32") 86 let b:browsefilter ..= "All Files (*.*)\t*\n" 87 else 88 let b:browsefilter ..= "All Files (*)\t*\n" 89 endif 90 let b:undo_ftplugin ..= " | unlet! b:browsefilter" 91 endif 92 93 let &cpo = s:cpo_save 94 unlet s:cpo_save