分类: C/C++
2011-02-27 07:04:24
转自: 利用c.vim插件,你可以实现
这一插件的作者是 Fritz Mehner, 目标就是打造程序员流畅的编辑环境。
$ wget 2: 安装$ mkdir ~/.vim $ cd ~/.vim $ unzip /usr/src/cvim.zipStep 3: 启用这一插件$ vim ~/.vimrc filetype plugin on8 c.vim的使用Feature 1: Add Automatic Header to *.c file 当你新建一个扩展名.c的文件时候,自动在文件头部增加头部注释 $ vim myprogram.c/* * ================================================= * Filename: myprogram.c * * Description: * * Version: 1.0 * Created: 01/19/09 20:23:25 * Revision: none * Compiler: gcc * * Author: Dr. Fritz Mehner (mn), * Company: FH Südwestfalen, Iserlohn * * ================================================= */
|AUTHOR| = geekstuff |AUTHORREF| = gk |EMAIL| = subscribe@geekstuff |COMPANY| = thegeekstuff.com
/* * ================================================= * * Filename: myprogram.c * * Description: * * Version: 1.0 * Created: 01/19/09 20:26:43 * Revision: none * Compiler: gcc * * Author: geekstuff (gk), subscribe@geekstuff * Company: thegeekstuff.com * * ================================================= */Feature 2: 用\if 添加c函数 键入\if 加函数名称 (as shown in Fig1 below) 就会在文件中自动完成函数的定义,就像图二那样。 Fig1:Insert C Function Automatically Fig 2:Insert C Function Automatically 添加的效果如下: Fig 3: Insert C main function automatically Fig 4: Insert C Function Header Automatically Fig 5: Insert C Function Header Automatically Fig 6: Insert a Frame Comment Automatically Type \p< in the normal mode, which will include the text “#include <>”, and places the cursor in the < symbol in Insert mode where you can type the header file name. Feature 7: 保存编译文件.保存并编译文件 \rc. 运行 \rr. Feature 8: 用\nr 插入预定义的代码片段The plugin comes with few pre-defined code snippets that you can insert into your code. Following are the default code snippets that comes with the plugin. $ ls ~/.vim/c-support/codesnippetsMakefile calloc_double_matrix.c main.c print_double_array.c.noindent Makefile.multi-target.template calloc_int_matrix.c main.cc print_int_array.c.noindent For example, if you want to create a function that will Allocate a dynamic int-matrix of size rows*columns; return a pointer, you can re-use it from the existing code snippets. Following is the content of the calloc_int_matrix.c pre-defined code snippets. /** === FUNCTION ====================================================================== * Name: calloc_int_matrix * Description: Allocate a dynamic int-matrix of size rows*columns; return a pointer. * ===================================================================================== */ int** calloc_int_matrix ( int rows, int columns ) { int i; int **m; m = calloc ( rows, sizeof(int*) ); /* allocate pointer array */ assert( m != NULL ); /* abort if allocation failed */ *m = calloc ( rows*columns, sizeof(int) ); /* allocate data array */ assert(*m != NULL ); /* abort if allocation failed */ for ( i=1; i m[i] = m[i-1] + columns; return m; } /* ———- end of function calloc_int_matrix ———- */ 如果要插入这段代码,可以键入\nr 文件名称,代码就会自动插入 |