vim 快速注释解决方案

留坑,待补,先附上资源

***********************************2014.2.24**************************

                                                                  补坑

*********************************************************************

  前言:vim-plugin插件一个集合多个语言环境实用vim 插件,目的是提供更加适宜的写代码环境,本文主要尝试讲解其中支持c语言的c-support部分。安装

vim-plugin可以使用vundle,非常方便,强烈推荐

   简介:  c.vim 是为vim/gvim写的支持插件.通过使用同意连续的代码风格,来加速项目的进度。而这种统一的风格是通过插入完整说明,代码片段,模板,和注释。同时该插件也可以让你仅仅使用键盘就能进行语法检验,编译,运行代码,或是运行一个代码检测器和重构器。

  使用帮助 :

   在非GUI环境下,尤其是一些经常被使用的命令会被映射到一些快捷建组合,这些组合会在这里被描述:资源,但要注意在普通模式下输入时必须快一些,因为做为引导符的'\',只会被识别一个短暂的时间。

   现在先让我们看看最酷炫查找帮助方式,你可以通过 \he \hd 可以通过浏览器分别获得当前光标下单词的wikitionary和Doxygen的解释,而 \hm 可以让打开该单词的帮助文件,\hp 是打开c.vim的帮助。

 

   好的代码应该有10%左右的注释内容,因此尽可能统一简明的注释风格是很重要的,c.vim就提供了一下映射建来快速注释。现在让我们好好的看看c.vim 如何提供快速的代码注释。

当你在bash输入下面命令时,你会打开vim,并且建立一个test.c的文件,这个全新的

vim test.c 

 

文件需要一个文件注释,来标明她是属于你的,c.vim就可以做到这一点,如果你安装了该插件,当test.c打开时,头部注释会自动出现

 

/*
 * =====================================================================================
 *
 *       Filename:  test.c
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2015年02月24日 23时18分16秒
 *       Revision:  none
 *       Compiler:  clang 
 *
 *         Author:  magichan (fgm), 574932286@qq.com
 *   Organization:  FH Südwestfalen, Iserlohn
 *           Rule:  ???? question 
 *                  [    comment
 *
 * =====================================================================================
 */

 

而你自己的信息可以通过修改插件文件夹里的 /templates/Templates文件内的变量,如果你是通过vundle安装vim-plugin插件获得c.vim插件的话,

具体路径在图片的最低部已经知识出来了

   如果这个头文件不是你想要的模式怎么办,容忍它?怎么可能,修改这个模板是很简单的。模板的路径,图片已经给你指示的很清楚了,当然这是建立在你使用vundle安装vim-plugin的前提下的

   PS:这是.c文件的头注释,.h文件也有单独的文件头注释,修改的方式类似。

 

 如果你设计好一个结构体,例如

print_double_array ( double array[],
           int n,
           int columns,
           char* arrayname
)

想给他们写上注释,这时在普通模式下 输入 [n]\cl (n 是从光标当前行往下操作n行,可以不输,默认操作为 1 )就可以得到下面的效果,你要做的是填注释

  print_double_array ( double array[],             /*  */
                       int    n,                    /*  */
                       int    columns,              /*  */
                       char*  arrayname,            /*  */
                       )

 当你想注释掉一端代码时 [n]\c* [n]\cc [n]\co,就是你需要的

对于这一段代码

 xxxxxxxx
 xxxxxxxx
 xxxxxxxx

输入 [n]\c* 时,会变成

 

 /* xxxxxxxx
  * xxxxxxxx
  * xxxxxxxx
  */

输入[n]\cc,会变成

 //xxxxxxxx
 //xxxxxxxx
 //xxxxxxxx

如果,你不想要注释的话,就使用[n]\co来清除他们

文件注释,代码注释,现在还缺少一个函数注释,\cfu 就是用来给函数提供注释模块的,它会让你先输入函数名,例如test,之后提供一个模板(下面这个是被修改过的,修改的方式可以参照修改文件注释)

/* 
 * ===  FUNCTION  ======================================================================
 *         Name:  test
 *  Description:  
 *        Entry:
 *         Exit:
 * =====================================================================================
 */

类似的注释快捷键,尤其是关于c++的还有很多,可以在 这里 查看,我再挑个好玩的说一下,

  \ct                   插入时间和日期

 

关于c的语法片段的快捷键:

\sd              do { } while (n,v,i)
\sf               for (n,i)
\sfo             for { } (n,v,i)
\si               if (n,i)
\sif              if { } (n,v,i)
\sie             if else (n,v,i)
\sife            if { } else { } (n,v,i)
\se              else { } (n,v,i)
\sw             while (n,i)
\swh           while { } (n,v,i)
\ss              switch (n,v,i)
\sc              case (n,i)
\sb              {} (n,v,i)         

 

 

 


-- Run ----------------------------------------------------------------

 

\rc save and compile (n,i)
\rl link (n,i)
\rr run (n,i)
\ra set comand line arguments (n,i)
\rd run debugger (n,i)

 

\re executable to run (n,i)

 

\rp run splint (n,i)
\rpa cmd. line arg. for splint (n,i)
\rcc run cppcheck (n,i)
\rccs severity for cppcheck (n,i)
\rk run CodeCheck (TM) (n,i)
\rka cmd. line arg. for CodeCheck (TM) (n,i)
\ri run indent (n,v,i)
[n]\rh hardcopy buffer (n,v,i)
\rs show plugin settings (n,i)
\rx set xterm size (n, only Linux/UNIX & GUI)
\ro change output destination (n,i)

 

 

-- Idioms -------------------------------------------------------------

 

\if function (n,v,i)
\isf function static (n,v,i)
\im main() (n,v,i)
\ie enum + typedef (n,i)
\is struct + typedef (n,i)
\iu union + typedef (n,i)
\isc scanf() (n,i)
\ipr printf() (n,i)
\ica p=calloc() (n,i)
\ima p=malloc() (n,i)
\ire p=realloc() (n,i)
\isi sizeof() (n,v,i)
\ias assert() (n,v)
\ii open input file (n,i)
\io open output file (n,i)
\ifsc fscanf (n,i)
\ifpr fprintf (n,i)
[n]\i0 for( x=0; x<n; x+=1 ) (n,v,i)
[n]\in for( x=n-1; x>=0; x-=1 ) (n,v,i)

 

-- Preprocessor -------------------------------------------------------

 

\pih include standard library header (n,i)
\piph include POSIX header (n,i)
\pg #include <> (global) (n,i)
\pl #include "" (local) (n,i)
\pd #define (n,i)
\pu #undef (n,i)
\pif #if #endif (n,v,i)
\pie #if #else #endif (n,v,i)
\pid #ifdef #else #endif (n,v,i)
\pin #ifndef #else #endif (n,v,i)
\pind #ifndef #def #endif (n,v,i)
\pe #error (n,i)
\pl #line (n,i)
\pp #pragma (n,i)
\pw #warning (n,i)
\pi0 #if 0 #endif (n,v,i)
\pr0 remove #if 0 #endif (n,i)

 

-- Snippets -----------------------------------------------------------

 

\nr read code snippet (n,i)
\nv view code snippet (read-only) (n,i)
\nw write code snippet (n,v,i)
\ne edit code snippet (n,i)

 

[n]\nf pick up function prototype (n,v,i)
[n]\np pick up function prototype (n,v,i)
[n]\nm pick up method prototype (n,v,i)
\ni insert prototype(s) (n,i)
\nc clear prototype(s) (n,i)
\ns show prototype(s) (n,i)

 

\ntl edit local templates (n,i)
\ntr reread templates (n,i)
\njt include jump tags (n,i)

 

-- C++ ----------------------------------------------------------------

 

\+ih include C++ standard library header (n,i)
\+ich include C standard library header (n,i)
\+om output manipulators (n,i)
\+fb ios flag bits (n,i)
\+c class (n,i)
\+cn class (using new) (n,i)
\+tc template class (n,i)
\+tcn template class (using new) (n,i)
\+ec error class (n,i)
\+tf template function (n,i)
\+tr try ... catch (n,v,i)
\+ca catch (n,v,i)
\+caa catch(...) (n,v,i)
\+ex extern "C" { } (n,v,i)
\+oif open input file (n,v,i)
\+oof open output file (n,v,i)
\+uns using namespace std; (n,v,i)
\+un using namespace xxx; (n,v,i)
\+unb namespace xxx { } (n,v,i)
\+na namespace alias (n,v,i)
\+rt RTTI (n,v,i)

 

\+ic class implementation (n,i)
\+icn class (using new) implementation (n,i)
\+im method implementation (n,i)
\+ia accessor implementation (n,i)
\+itc template class implementation (n,i)
\+itcn template class (using new) impl. (n,i)
\+itm template method implementation (n,i)
\+ita template accessor implementation (n,i)
\+ioi operator >> (n,i)
\+ioo operator << (n,i)

 

posted on 2015-01-28 20:41  独独  阅读(2478)  评论(0编辑  收藏  举报

导航