"###############################################################################################
"
" Filename: c.vim
"
" Description: Statement oriented editing of C/C++ programs (VIM Version 6.0+)
"
" - insertion of comments, statements and idioms
" - compile/link/run support for one-file projects (without a makefile)
"
" Code and comments should have a professional appearance and should be
" easy to write and maintain.
" Programs with a consistent style are easier to read and understand.
" The standardization of comments makes it possible to automate the search
" for information and the generation of documents from the source code.
"
" Author: Dr.-Ing. Fritz Mehner
" Fachhochschule Südwestfalen, Iserlohn, Germany
"
" Email: mehner@fh-swf.de
"
" Usage: (1.0) Configure c.vim (section Configuration below).
" (2.1) Load c.vim manually into VIM with the 'so' command:
" :so ~//c.vim
" or better
" (2.2) Load c.vim on startup (VIM version 6.0 and higher) :
" move this file to the directory ~/.vim/plugin/
" c.vim inserts an additional menu entry into the Tools-menu for
" loading/unloading the C support.
"
" Note: The register z is used in many places.
"
" Style Guides: Some ideas are taken from the following documents (recommended!):
"
" 1. Recommended C Style and Coding Standards (Indian Hill Style Guide)
" www.doc.ic.ac.uk/lab/secondyear/cstyle/cstyle.html
" 2. Programming in C++, Ellemtel Telecommunication Systems Laboratories
" www.it.bton.ac.uk/burks/burks/language/cpp/cppstyle/ellhome.htm
" 3. C++ Coding Standard, Todd Hoff
" www.possibility.com/Cpp/CppCodingStandard.html
"
let s:CVIM_Version = "2.1" " version number of this script; do not change
" Revision: 04.04.2002
" Created: 11.03.2002
"###############################################################################################
"
" Configuration (Use my configuration as an example)
"
"-------------------------------------------------------------------------------------
"
let s:CVIM_AuthorName = "Dr.-Ing. Fritz Mehner"
let s:CVIM_AuthorRef = "Mn"
"
" The following entries do not appear if the strings are empty.
"
let s:CVIM_Email = "mehner@fh-swf.de"
let s:CVIM_Company = "Fachhochschule Südwestfalen, Iserlohn"
let s:CVIM_Project = ""
let s:CVIM_Compiler = "GNU C/C++"
"
" Copyright information
" ---------------------
" If the code has been developed over a period of years, each year must be stated.
" If CVIM_CopyrightHolder is empty the copyright notice will not appear.
" If CVIM_CopyrightHolder is not empty and CVIM_CopyrightYears is empty,
" the current year will be inserted.
"
let s:CVIM_CopyrightHolder = ""
let s:CVIM_CopyrightYears = ""
"
"###############################################################################################
"
" Global Variables : Compiler, Options, Libraries, ...
"
"-------------------------------------------------------------------------------------
"
let s:CVIM_CExtension = "c" " C file extension; everything else is C++
let s:CVIM_CCompiler = "gcc" " the C compiler
let s:CVIM_CplusCompiler = "g++" " the C++ compiler
let s:CVIM_CFlags = "-Wall -g -c" " compiler flags: compile
let s:CVIM_LFlags = "-Wall -g" " compiler flags: link
let s:CVIM_Libs = "-lm" " libraries to use
"
let s:CVIM_Pager = "less" " pager
"
let s:CVIM_CmdLineArgs = "" " command line arguments for Run-run;
" " initially empty
"###############################################################################################
"
" ... finally
"
" Johann Wolfgang von Goethe (1749-1832), the greatest of the german men of letters,
" about LINUX, Vim/gVim and other great tools (Ok, almost.) :
"
" "Ein Mann, der recht zu wirken denkt, "Who on efficient work is bent,
" Muß auf das beste Werkzeug halten." Must choose the fittest instrument."
"
" Faust, Teil 1, Vorspiel auf dem Theater Faust, Part 1, Prologue for the Theatre
"
"###############################################################################################
"------------------------------------------------------------------------------
" C : CVIM_InitC
" Initialization of C support menus
"------------------------------------------------------------------------------
"
function! CVIM_InitC ()
"
"===============================================================================================
"----- Menu : Key Mappings ---------------------------------------------------------------------
"===============================================================================================
" The following key mappings are for convenience only.
" Comment out the mappings if you dislike them.
" If enabled, there may be conflicts with predefined key bindings of your window manager.
"-------------------------------------------------------------------------------------
" Alt-F9 write buffer and compile
" F9 compile and link
" Ctrl-F9 run executable
"
map :w:call CVIM_Compile():cwin
map :call CVIM_Link():cwin
map :call CVIM_Run(0):cwin
"
"===============================================================================================
"----- Menu : C-Comments -----------------------------------------------------------------------
"===============================================================================================
" MENU ENTRY
" -----------------
" Line End Comment
" Frame Comment
" Function Description (grep searchable with "^//#" )
" Main Description (grep searchable with "^//#" )
" File Prologue (grep searchable with "^//#" )
" File Section Headers
" Keyword Comments (grep searchable with "// :" )
" Comment out a highlighted block of code
" Uncomment a highlighted block of code
" Date+Time
" Date
" Special Comments (reminders)
"===============================================================================================
"
amenu C-&Comments.&Line\ End\ Comment A//
amenu C-&Comments.&Frame\ Comment :call CVIM_CommentFrame() jA
amenu C-&Comments.F&unction\ Description :call CVIM_CommentFunction() :/NameA
amenu C-&Comments.&Main\ Description :call CVIM_CommentMain() :/DescriptionA
amenu C-&Comments.File\ &Prologue :call CVIM_CommentFilePrologue():/DescriptionA
amenu C-&Comments.-SEP1- :
"
"----- Submenu : C++ : file sections -------------------------------------------------------------
"
amenu C-&Comments.C-File\ &Sections.&Header\ File\ Includes :call CVIM_CommentSection("HEADER FILE INCLUDES") 0i
amenu C-&Comments.C-File\ &Sections.&Macros :call CVIM_CommentSection("MACROS") 0i
amenu C-&Comments.C-File\ &Sections.M&acros\ with\ Arguments :call CVIM_CommentSection("MACROS WITH ARGUMENTS") 0i
amenu C-&Comments.C-File\ &Sections.&Type\ Definitions :call CVIM_CommentSection("TYPE DEFINITIONS") 0i
amenu C-&Comments.C-File\ &Sections.&Enumerations :call CVIM_CommentSection("ENUMERATIONS") 0i
amenu C-&Comments.C-File\ &Sections.E&xtern\ Data :call CVIM_CommentSection("EXTERN DATA") 0i
amenu C-&Comments.C-File\ &Sections.&Non-static\ Global\ Data :call CVIM_CommentSection("NON-STATIC GLOBAL DATA")0i
amenu C-&Comments.C-File\ &Sections.&Static\ Global\ Data :call CVIM_CommentSection("STATIC GLOBAL DATA") 0i
amenu C-&Comments.C-File\ &Sections.&Local\ Prototypes :call CVIM_CommentSection("LOCAL PROTOTYPES") 0i
amenu C-&Comments.C-File\ &Sections.&Functions :call CVIM_CommentSection("FUNCTIONS") 0i
amenu C-&Comments.C-File\ &Sections.-\ All\ Se&ctions :call CVIM_CommentSectionAll() 0i
"
"----- Submenu : C++ : keyword comments ----------------------------------------------------------
"
amenu C-&Comments.\/\/\ \:&KEYWORD\:.&BUG $:call CVIM_CommentClassified("BUG") kgJA
amenu C-&Comments.\/\/\ \:&KEYWORD\:.&COMPILER $:call CVIM_CommentClassified("COMPILER")kgJA
amenu C-&Comments.\/\/\ \:&KEYWORD\:.&TODO $:call CVIM_CommentClassified("TODO") kgJA
amenu C-&Comments.\/\/\ \:&KEYWORD\:.T&RICKY $:call CVIM_CommentClassified("TRICKY") kgJA
amenu C-&Comments.\/\/\ \:&KEYWORD\:.&WARNING $:call CVIM_CommentClassified("WARNING") kgJA
amenu C-&Comments.\/\/\ \:&KEYWORD\:.&new\ keyword $:call CVIM_CommentClassified("") kgJf:a
"
amenu C-&Comments.-SEP2- :
vmenu C-&Comments.&code->comment :'<,'>s/^/\/\//:nohlsearch
vmenu C-&Comments.c&omment->code :'<,'>s/^\/\///
amenu C-&Comments.-SEP3- :
amenu C-&Comments.&Date :let @z=strftime("%x")"zpa
amenu C-&Comments.Date\ &Time :let @z=strftime("%x - %X")"zpa
"
amenu C-&Comments.-SEP5- :
amenu C-&Comments.\/\/\ &EMPTY A// EMPTY
amenu C-&Comments.\/\/\ FALL\ TH&ROUGH A// FALL THROUGH
amenu C-&Comments.\/\/\ &IMPLICIT\ TYPE\ CONV A// IMPLICIT TYPE CONVERSION
amenu C-&Comments.\/\/\ &NOT\ REACHED A// NOT REACHED
"
"===============================================================================================
"----- Menu : C-Statements ---------------------------------------------------------------------
"===============================================================================================
" MENU ENTRY
" -----------------
" if { }
" if { } else { }
" else { }
" for
" for { }
" while { }
" do { } while
" switch
" case
" { }
" #include <...>
" #include "..."
" #define
" #ifndef..#def..#endif
" #ifdef..#endif
"===============================================================================================
"
imenu C-St&atements.&if\ \{\ \} :let @z="if ( )\n{\n\t\n}\n" "z]pf(la
imenu C-St&atements.if\ \{\ \}\ &else\ \{\ \} :let @z="if ( )\n{\n\t\n}\nelse\n{\n\t\n}\n" "z]pf(la
imenu C-St&atements.e&lse\ \{\ \} :let @z="else\n{\n\t\n}\n" "z]p4<<2ja
imenu C-St&atements.&for :let @z="for ( ; ; )\n" "z]pf;i
imenu C-St&atements.f&or\ \{\ \} :let @z="for ( ; ; )\n{\n\t\n}\n" "z]pf;i
imenu C-St&atements.&while\ \{\ \} :let @z="while ( )\n{\n\t\n}\n" "z]pf(la
imenu C-St&atements.&do\ \{\ \}\ while :call CVIM_DoWhile() "z]p:/while f(la
imenu C-St&atements.&switch :call CVIM_CodeSwitch() "z]pf(la
imenu C-St&atements.&case :call CVIM_CodeCase() "z]pf:i
imenu C-St&atements.&\{\ \} :let @z="{\n\t\n}\n" "z]pjA
imenu C-St&atements.-SEP1- :
imenu C-St&atements.#include\ &\<\.\.\.\> :let @z="#include\t<.h>" "zpF.i
imenu C-St&atements.#include\ \"\.\.\.\" :let @z="#include\t\".h\"" "zpF.i
imenu C-St&atements.&#define :let @z="#define\t\t\t\t// " "zp4Fa
imenu C-St&atements.#if\.\.#else\.\.#endif :call CVIM_PPIfElse('if') ji
imenu C-St&atements.#ifdef\.\.#else\.\.#endif :call CVIM_PPIfElse('ifdef') ji
imenu C-St&atements.#ifndef\.\.#else\.\.#endif :call CVIM_PPIfElse('ifndef') ji
imenu C-St&atements.#ifndef\.\.#def\.\.#endif :call CVIM_PPIfDef() 2ji
"
"===============================================================================================
"----- Menu : C-Idioms -------------------------------------------------------------------------
"===============================================================================================
" MENU ENTRY
" -----------------
" function
" main
" for( i=0; i=0; i-=1 )
" for( i=1; i<=n; i+=1 )
" for( i=n; i>=1; i-=1 )
" enum + typedef
" struct + typedef
" union + typedef
" printf
" scanf
" #include
" p=malloc( )
" open input file
" open output file
"===============================================================================================
"
imenu C-&Idioms.&function :call CVIM_CodeFunction()
imenu C-&Idioms.&main :call CVIM_CodeMain() 3jA
imenu C-&Idioms.-SEP1- :
imenu C-&Idioms.for\ (\ i=&0;\ \ \ i0fni
imenu C-&Idioms.for\ (\ i=n&-1;\ i>=0;\ i\-=1\ ) for ( i=n-1; i>=0; i-=1 )0fni
imenu C-&Idioms.for\ (\ i=&1;\ \ \ i<=n;\ i\+=1\ ) for ( i=1; i<=n; i+=1 )0fni
imenu C-&Idioms.for\ (\ i=&n;\ \ \ i>=1;\ i\-=1\ ) for ( i=n; i>=1; i-=1 )0fni
imenu C-&Idioms.-SEP2- :
imenu C-&Idioms.&enum\+typedef :call CVIM_EST("enum") 2jA
imenu C-&Idioms.&struct\+typedef :call CVIM_EST("struct") 2jA
imenu C-&Idioms.&union\+typedef :call CVIM_EST("union") 2jA
imenu C-&Idioms.-SEP3- :
imenu C-&Idioms.&printf printf ("\n");2F"a
imenu C-&Idioms.s&canf scanf ("", & );F"i
"
"----- Submenu : C-Idioms: standard library -------------------------------------------------------
"
imenu C-&Idioms.&#include\ Std\.Lib\..\<&assert\.h\> o#include
imenu C-&Idioms.&#include\ Std\.Lib\..\<&ctype\.h\> o#include
imenu C-&Idioms.&#include\ Std\.Lib\..\<&errno\.h\> o#include
imenu C-&Idioms.&#include\ Std\.Lib\..\<&float\.h\> o#include
imenu C-&Idioms.&#include\ Std\.Lib\..\<&limits\.h\> o#include
imenu C-&Idioms.&#include\ Std\.Lib\..\ o#include
imenu C-&Idioms.&#include\ Std\.Lib\..\<&math\.h\> o#include
imenu C-&Idioms.&#include\ Std\.Lib\..\ o#include
imenu C-&Idioms.&#include\ Std\.Lib\..\ o#include
imenu C-&Idioms.&#include\ Std\.Lib\..\ o#include
imenu C-&Idioms.&#include\ Std\.Lib\..\ o#include
imenu C-&Idioms.&#include\ Std\.Lib\..\<&stdio\.h\> o#include
imenu C-&Idioms.&#include\ Std\.Lib\..\ o#include
imenu C-&Idioms.&#include\ Std\.Lib\..\ o#include
imenu C-&Idioms.&#include\ Std\.Lib\..\<&time\.h\> o#include
"
imenu C-&Idioms.-SEP4- :
imenu C-&Idioms.p=m&alloc\(\ \) :call CVIM_CodeMalloc() f(la
imenu C-&Idioms.open\ &input\ file :call CVIM_CodeFopenRead() jf"a
imenu C-&Idioms.open\ &output\ file :call CVIM_CodeFopenWrite() jf"a
"===============================================================================================
"----- Menu : C++ ------------------------------------------------------------------------------
"===============================================================================================
" MENU ENTRY
" -----------------
" cout variable
" cout string
" cin
" cerr
" #include
" class
" class using new
" template function
" template class
" friend operator <<
" friend operator >>
" try .. catch
" catch( )
" catch(...)
" open input file
" open output file
" using namespace
" namespace
"===============================================================================================
"
imenu C&++.cout\ &variable cout<< "\n" << ;i
imenu C&++.cout\ &string cout<< "\n";hi
imenu C&++.c&in cin>> ;i
"
"----- Submenu : C++ : output manipulators -------------------------------------------------------
"
imenu C&++.output\ mani&pulators.\<\<\ &endl << endl a
imenu C&++.output\ mani&pulators.\<\<\ &flush << flush a
imenu C&++.output\ mani&pulators.\<\<\ &dec << dec a
imenu C&++.output\ mani&pulators.\<\<\ &hex << hex a
imenu C&++.output\ mani&pulators.\<\<\ &oct << oct a
imenu C&++.output\ mani&pulators.\<\<\ set&base\(\ \) << setbase() F)i
imenu C&++.output\ mani&pulators.\<\<\ setfi&ll\(\ \) << setfill() F)i
imenu C&++.output\ mani&pulators.\<\<\ set&iosflag\(\ \) << setiosflag() F)i
imenu C&++.output\ mani&pulators.\<\<\ &resetiosflag\(\ \) << resetiosflag() F)i
imenu C&++.output\ mani&pulators.\<\<\ set&precision\(\ \) << setprecision() F)i
imenu C&++.output\ mani&pulators.\<\<\ set&w\(\ \) << setw() F)i
imenu C&++.output\ mani&pulators.&#include\ \ :let @z="#include\t" "z]pa
"
"----- Submenu : C++ : ios flag bits -------------------------------------------------------------
"
imenu C&++.ios\ fla&gbits.ios::&skipws ios::skipwsa
imenu C&++.ios\ fla&gbits.ios::&left ios::lefta
imenu C&++.ios\ fla&gbits.ios::&right ios::righta
imenu C&++.ios\ fla&gbits.ios::&internal ios::internala
imenu C&++.ios\ fla&gbits.ios::&boolalpha ios::boolalpha