" ------------------------------------------------------------------------------ " " Vim filetype plugin file " " Language : C / C++ " Plugin : c.vim " Maintainer : Fritz Mehner " Revision : $Id: c.vim,v 1.58 2010/05/14 19:13:40 mehner Exp $ " " ------------------------------------------------------------------------------ " " Only do this when not done yet for this buffer " if exists("b:did_C_ftplugin") finish endif let b:did_C_ftplugin = 1 " " ---------- Do we have a mapleader other than '\' ? ------------ " if exists("g:C_MapLeader") let maplocalleader = g:C_MapLeader endif " " ---------- C/C++ dictionary ----------------------------------- " This will enable keyword completion for C and C++ " using Vim's dictionary feature |i_CTRL-X_CTRL-K|. " Set the new dictionaries in front of the existing ones " if exists("g:C_Dictionary_File") let save=&dictionary silent! exe 'setlocal dictionary='.g:C_Dictionary_File silent! exe 'setlocal dictionary+='.save endif " " ---------- F-key mappings ------------------------------------ " " Alt-F9 write buffer and compile " F9 compile and link " Ctrl-F9 run executable " Shift-F9 command line arguments " map :call C_Compile():call C_HlMessage() imap :call C_Compile():call C_HlMessage() " map :call C_Link():call C_HlMessage() imap :call C_Link():call C_HlMessage() " map :call C_Run() imap :call C_Run() " map :call C_Arguments() imap :call C_Arguments() " " ---------- alternate file plugin (a.vim) ---------------------- " if exists("loaded_alternateFile") map :A imap :A endif " command! -nargs=1 -complete=customlist,C_CFileSectionList CFileSection call C_CFileSectionListInsert () command! -nargs=1 -complete=customlist,C_HFileSectionList HFileSection call C_HFileSectionListInsert () command! -nargs=1 -complete=customlist,C_KeywordCommentList KeywordComment call C_KeywordCommentListInsert () command! -nargs=1 -complete=customlist,C_SpecialCommentList SpecialComment call C_SpecialCommentListInsert () command! -nargs=1 -complete=customlist,C_StdLibraryIncludesList IncludeStdLibrary call C_StdLibraryIncludesInsert () command! -nargs=1 -complete=customlist,C_C99LibraryIncludesList IncludeC99Library call C_C99LibraryIncludesInsert () command! -nargs=1 -complete=customlist,C_CppLibraryIncludesList IncludeCppLibrary call C_CppLibraryIncludesInsert () command! -nargs=1 -complete=customlist,C_CppCLibraryIncludesList IncludeCppCLibrary call C_CppCLibraryIncludesInsert() command! -nargs=1 -complete=customlist,C_StyleList CStyle call C_Style () " ---------- KEY MAPPINGS : MENU ENTRIES ------------------------------------- " ---------- comments menu ------------------------------------------------ " noremap cl :call C_LineEndComment() inoremap cl :call C_LineEndComment() vnoremap cl :call C_MultiLineEndComments()a noremap cj :call C_AdjustLineEndComm("a") vnoremap cj :call C_AdjustLineEndComm("v") inoremap cj :call C_AdjustLineEndComm("a")a noremap cs :call C_GetLineEndCommCol() noremap c* :call C_CodeComment("a","yes"):nohlsearchj vnoremap c* :call C_CodeComment("v","yes"):nohlsearchj noremap cc :call C_CodeComment("a","no"):nohlsearchj vnoremap cc :call C_CodeComment("v","no"):nohlsearchj noremap co :call C_CommentCode("a"):nohlsearch vnoremap co :call C_CommentCode("v"):nohlsearch noremap cfr :call C_InsertTemplate("comment.frame") noremap cfu :call C_InsertTemplate("comment.function") noremap cme :call C_InsertTemplate("comment.method") noremap ccl :call C_InsertTemplate("comment.class") noremap cfdi :call C_InsertTemplate("comment.file-description") noremap cfdh :call C_InsertTemplate("comment.file-description-header") inoremap cfr :call C_InsertTemplate("comment.frame") inoremap cfu :call C_InsertTemplate("comment.function") inoremap cme :call C_InsertTemplate("comment.method") inoremap ccl :call C_InsertTemplate("comment.class") inoremap cfdi :call C_InsertTemplate("comment.file-description") inoremap cfdh :call C_InsertTemplate("comment.file-description-header") noremap cd :call C_InsertDateAndTime('d') inoremap cd :call C_InsertDateAndTime('d')a vnoremap cd s:call C_InsertDateAndTime('d')a noremap ct :call C_InsertDateAndTime('dt') inoremap ct :call C_InsertDateAndTime('dt')a vnoremap ct s:call C_InsertDateAndTime('dt')a " " call the above defined commands: " noremap ccs :CFileSection noremap chs :HFileSection noremap ckc :KeywordComment noremap csc :SpecialComment " inoremap ccs :CFileSection inoremap chs :HFileSection inoremap ckc :KeywordComment inoremap csc :SpecialComment " " ---------- statements menu ------------------------------------------------ " noremap sd :call C_InsertTemplate("statements.do-while") vnoremap sd :call C_InsertTemplate("statements.do-while", "v") inoremap sd :call C_InsertTemplate("statements.do-while") noremap sf :call C_InsertTemplate("statements.for") inoremap sf :call C_InsertTemplate("statements.for") noremap sfo :call C_InsertTemplate("statements.for-block") vnoremap sfo :call C_InsertTemplate("statements.for-block", "v") inoremap sfo :call C_InsertTemplate("statements.for-block") noremap si :call C_InsertTemplate("statements.if") inoremap si :call C_InsertTemplate("statements.if") noremap sif :call C_InsertTemplate("statements.if-block") vnoremap sif :call C_InsertTemplate("statements.if-block", "v") inoremap sif :call C_InsertTemplate("statements.if-block") noremap sie :call C_InsertTemplate("statements.if-else") vnoremap sie :call C_InsertTemplate("statements.if-else", "v") inoremap sie :call C_InsertTemplate("statements.if-else") noremap sife :call C_InsertTemplate("statements.if-block-else") vnoremap sife :call C_InsertTemplate("statements.if-block-else", "v") inoremap sife :call C_InsertTemplate("statements.if-block-else") noremap se :call C_InsertTemplate("statements.else-block") vnoremap se :call C_InsertTemplate("statements.else-block", "v") inoremap se :call C_InsertTemplate("statements.else-block") noremap sw :call C_InsertTemplate("statements.while") inoremap sw :call C_InsertTemplate("statements.while") noremap swh :call C_InsertTemplate("statements.while-block") vnoremap swh :call C_InsertTemplate("statements.while-block", "v") inoremap swh :call C_InsertTemplate("statements.while-block") noremap ss :call C_InsertTemplate("statements.switch") vnoremap ss :call C_InsertTemplate("statements.switch", "v") inoremap ss :call C_InsertTemplate("statements.switch") noremap sc :call C_InsertTemplate("statements.case") inoremap sc :call C_InsertTemplate("statements.case") noremap s{ :call C_InsertTemplate("statements.block") vnoremap s{ :call C_InsertTemplate("statements.block", "v") inoremap s{ :call C_InsertTemplate("statements.block") noremap sb :call C_InsertTemplate("statements.block") vnoremap sb :call C_InsertTemplate("statements.block", "v") inoremap sb :call C_InsertTemplate("statements.block") " " ---------- preprocessor menu ---------------------------------------------- "" noremap ps :IncludeStdLibrary inoremap ps :IncludeStdLibrary noremap pc :IncludeC99Library inoremap pc :IncludeC99Library noremap +ps :IncludeCppLibrary inoremap +ps :IncludeCppLibrary noremap +pc :IncludeCppCLibrary inoremap +pc :IncludeCppC9Library " noremap p< :call C_InsertTemplate("preprocessor.include-global") noremap p" :call C_InsertTemplate("preprocessor.include-local") noremap pd :call C_InsertTemplate("preprocessor.define") noremap pu :call C_InsertTemplate("preprocessor.undefine") " inoremap p< :call C_InsertTemplate("preprocessor.include-global") inoremap p" :call C_InsertTemplate("preprocessor.include-local") inoremap pd :call C_InsertTemplate("preprocessor.define") inoremap pu :call C_InsertTemplate("preprocessor.undefine") noremap pie :call C_InsertTemplate("preprocessor.if-else-endif") noremap pid :call C_InsertTemplate("preprocessor.ifdef-else-endif") noremap pin :call C_InsertTemplate("preprocessor.ifndef-else-endif") noremap pind :call C_InsertTemplate("preprocessor.ifndef-def-endif") vnoremap pie :call C_InsertTemplate("preprocessor.if-else-endif", "v") vnoremap pid :call C_InsertTemplate("preprocessor.ifdef-else-endif", "v") vnoremap pin :call C_InsertTemplate("preprocessor.ifndef-else-endif", "v") vnoremap pind :call C_InsertTemplate("preprocessor.ifndef-def-endif", "v") inoremap pie :call C_InsertTemplate("preprocessor.if-else-endif") inoremap pid :call C_InsertTemplate("preprocessor.ifdef-else-endif") inoremap pin :call C_InsertTemplate("preprocessor.ifndef-else-endif") inoremap pind :call C_InsertTemplate("preprocessor.ifndef-def-endif") noremap pi0 :call C_PPIf0("a")2ji inoremap pi0 :call C_PPIf0("a")2ji vnoremap pi0 :call C_PPIf0("v") noremap pr0 :call C_PPIf0Remove() inoremap pr0 :call C_PPIf0Remove() " noremap pe :call C_InsertTemplate("preprocessor.error") noremap pl :call C_InsertTemplate("preprocessor.line") noremap pp :call C_InsertTemplate("preprocessor.pragma") " inoremap pe :call C_InsertTemplate("preprocessor.error") inoremap pl :call C_InsertTemplate("preprocessor.line") inoremap pp :call C_InsertTemplate("preprocessor.pragma") " " ---------- idioms menu ---------------------------------------------------- " noremap if :call C_InsertTemplate("idioms.function") vnoremap if :call C_InsertTemplate("idioms.function", "v") inoremap if :call C_InsertTemplate("idioms.function") noremap isf :call C_InsertTemplate("idioms.function-static") vnoremap isf :call C_InsertTemplate("idioms.function-static", "v") inoremap isf :call C_InsertTemplate("idioms.function-static") noremap im :call C_InsertTemplate("idioms.main") vnoremap im :call C_InsertTemplate("idioms.main", "v") inoremap im :call C_InsertTemplate("idioms.main") " noremap i0 :call C_CodeFor("up" , "a") vnoremap i0 :call C_CodeFor("up" , "v") inoremap i0 :call C_CodeFor("up" , "a")i noremap in :call C_CodeFor("down", "a") vnoremap in :call C_CodeFor("down", "v") inoremap in :call C_CodeFor("down", "a")i " noremap ie :call C_InsertTemplate("idioms.enum") vnoremap ie :call C_InsertTemplate("idioms.enum" , "v") inoremap ie :call C_InsertTemplate("idioms.enum") noremap is :call C_InsertTemplate("idioms.struct") vnoremap is :call C_InsertTemplate("idioms.struct", "v") inoremap is :call C_InsertTemplate("idioms.struct") noremap iu :call C_InsertTemplate("idioms.union") vnoremap iu :call C_InsertTemplate("idioms.union" , "v") inoremap iu :call C_InsertTemplate("idioms.union") " noremap ip :call C_InsertTemplate("idioms.printf") inoremap ip :call C_InsertTemplate("idioms.printf") noremap isc :call C_InsertTemplate("idioms.scanf") inoremap isc :call C_InsertTemplate("idioms.scanf") " noremap ica :call C_InsertTemplate("idioms.calloc") inoremap ica :call C_InsertTemplate("idioms.calloc") noremap ima :call C_InsertTemplate("idioms.malloc") inoremap ima :call C_InsertTemplate("idioms.malloc") " noremap isi :call C_InsertTemplate("idioms.sizeof") inoremap isi :call C_InsertTemplate("idioms.sizeof") vnoremap isi :call C_InsertTemplate("idioms.sizeof", "v") noremap ias :call C_InsertTemplate("idioms.assert") vnoremap ias :call C_InsertTemplate("idioms.assert", "v") inoremap ias :call C_InsertTemplate("idioms.assert") " noremap ii :call C_InsertTemplate("idioms.open-input-file") inoremap ii :call C_InsertTemplate("idioms.open-input-file") vnoremap ii :call C_InsertTemplate("idioms.open-input-file", "v") noremap io :call C_InsertTemplate("idioms.open-output-file") inoremap io :call C_InsertTemplate("idioms.open-output-file") vnoremap io :call C_InsertTemplate("idioms.open-output-file", "v") " " ---------- snippet menu ---------------------------------------------------- " noremap nr :call C_CodeSnippet("r") noremap nw :call C_CodeSnippet("w") vnoremap nw :call C_CodeSnippet("wv") noremap ne :call C_CodeSnippet("e") " inoremap nr :call C_CodeSnippet("r") inoremap nw :call C_CodeSnippet("w") inoremap ne :call C_CodeSnippet("e") " noremap np :call C_ProtoPick("n") vnoremap np :call C_ProtoPick("v") noremap ni :call C_ProtoInsert() noremap nc :call C_ProtoClear() noremap ns :call C_ProtoShow() " inoremap np :call C_ProtoPick("n") inoremap ni :call C_ProtoInsert() inoremap nc :call C_ProtoClear() inoremap ns :call C_ProtoShow() " noremap ntl :call C_EditTemplates("local") noremap ntg :call C_EditTemplates("global") noremap ntr :call C_RereadTemplates() noremap nts :CStyle " " ---------- C++ menu ---------------------------------------------------- " noremap +co :call C_InsertTemplate("cpp.cout") inoremap +co :call C_InsertTemplate("cpp.cout") " noremap +c :call C_InsertTemplate("cpp.class-definition") inoremap +c :call C_InsertTemplate("cpp.class-definition") noremap +cn :call C_InsertTemplate("cpp.class-using-new-definition") inoremap +cn :call C_InsertTemplate("cpp.class-using-new-definition") noremap +ci :call C_InsertTemplate("cpp.class-implementation") inoremap +ci :call C_InsertTemplate("cpp.class-implementation") noremap +cni :call C_InsertTemplate("cpp.class-using-new-implementation") inoremap +cni :call C_InsertTemplate("cpp.class-using-new-implementation") noremap +mi :call C_InsertTemplate("cpp.method-implementation") inoremap +mi :call C_InsertTemplate("cpp.method-implementation") noremap +ai :call C_InsertTemplate("cpp.accessor-implementation") inoremap +ai :call C_InsertTemplate("cpp.accessor-implementation") noremap +tc :call C_InsertTemplate("cpp.template-class-definition") inoremap +tc :call C_InsertTemplate("cpp.template-class-definition") noremap +tcn :call C_InsertTemplate("cpp.template-class-using-new-definition") inoremap +tcn :call C_InsertTemplate("cpp.template-class-using-new-definition") noremap +tci :call C_InsertTemplate("cpp.template-class-implementation") inoremap +tci :call C_InsertTemplate("cpp.template-class-implementation") noremap +tcni :call C_InsertTemplate("cpp.template-class-using-new-implementation") inoremap +tcni :call C_InsertTemplate("cpp.template-class-using-new-implementation") noremap +tmi :call C_InsertTemplate("cpp.template-method-implementation") inoremap +tmi :call C_InsertTemplate("cpp.template-method-implementation") noremap +tai :call C_InsertTemplate("cpp.template-accessor-implementation") inoremap +tai :call C_InsertTemplate("cpp.template-accessor-implementation") noremap +tf :call C_InsertTemplate("cpp.template-function") inoremap +tf :call C_InsertTemplate("cpp.template-function") noremap +ec :call C_InsertTemplate("cpp.error-class") inoremap +ec :call C_InsertTemplate("cpp.error-class") noremap +tr :call C_InsertTemplate("cpp.try-catch") vnoremap +tr :call C_InsertTemplate("cpp.try-catch", "v") inoremap +tr :call C_InsertTemplate("cpp.try-catch") noremap +ca :call C_InsertTemplate("cpp.catch") vnoremap +ca :call C_InsertTemplate("cpp.catch", "v") inoremap +ca :call C_InsertTemplate("cpp.catch") noremap +c. :call C_InsertTemplate("cpp.catch-points") vnoremap +c. :call C_InsertTemplate("cpp.catch-points", "v") inoremap +c. :call C_InsertTemplate("cpp.catch-points") " " ---------- run menu -------------------------------------------------------- " map rc :call C_Compile():call C_HlMessage() map rl :call C_Link():call C_HlMessage() map rr :call C_Run() map ra :call C_Arguments() map rm :call C_Make() map rma :call C_MakeArguments() map rp :call C_SplintCheck():call C_HlMessage() map rpa :call C_SplintArguments() map rd :call C_Indent() map rh :call C_Hardcopy("n") map rs :call C_Settings() " vmap rh :call C_Hardcopy("v") " imap rc :call C_Compile():call C_HlMessage() imap rl :call C_Link():call C_HlMessage() imap rr :call C_Run() imap ra :call C_Arguments() imap rm :call C_Make() imap rma :call C_MakeArguments() imap rp :call C_SplintCheck():call C_HlMessage() imap rpa :call C_SplintArguments() imap rd :call C_Indent() imap rh :call C_Hardcopy("n") imap rs :call C_Settings() if has("unix") map rx :call C_XtermSize() imap rx :call C_XtermSize() endif map ro :call C_Toggle_Gvim_Xterm() imap ro :call C_Toggle_Gvim_Xterm() " " Abraxas CodeCheck (R) " if executable("check") map rk :call C_CodeCheck():call C_HlMessage() map rka :call C_CodeCheckArguments() imap rk :call C_CodeCheck():call C_HlMessage() imap rka :call C_CodeCheckArguments() endif " ---------- plugin help ----------------------------------------------------- " map hp :call C_HelpCsupport() imap hp :call C_HelpCsupport() map hm :call C_Help("m") imap hm :call C_Help("m") " "------------------------------------------------------------------------------- " additional mapping : complete a classical C comment: '/*' => '/* | */' "------------------------------------------------------------------------------- inoremap /* /**/ vnoremap /* s/**/p " "------------------------------------------------------------------------------- " additional mapping : complete a classical C multi-line comment: " '/*' => /* " * | " */ "------------------------------------------------------------------------------- inoremap /* /*/kA " "------------------------------------------------------------------------------- " additional mapping : { always opens a block "------------------------------------------------------------------------------- inoremap { {}O vnoremap { S{}Pk=iB " " if !exists("g:C_Ctrl_j") || ( exists("g:C_Ctrl_j") && g:C_Ctrl_j != 'off' ) nmap i=C_JumpCtrlJ() imap =C_JumpCtrlJ() endif