用c.vim外掛程式打造C/C++整合編輯器

來源:互聯網
上載者:User
文章目錄
  • Step 1: 下載c.vim
  • Step 2: 安裝
  • Step 3: 啟用這一外掛程式
  • Feature 1: Add Automatic Header to *.c file
  • Feature 2: 用"if 添加c函數
  • Feature 3: 用"im 添加main函數
  • Feature 5:  用"cfr添加註釋架構
  • Feature 6: 用"p<包含標頭檔
  • Feature 7: 儲存編譯檔案.
  • Feature 8: 用"nr 插入預定義的程式碼片段
利用c.vim外掛程式,你可以實現

  • 添加檔案頭 
  • 添加註釋 
  • 插入一些程式碼片段 
  • 語法檢查 
  • 讀函數文檔 
  • 注釋代碼塊

這一外掛程式的作者是 Fritz Mehner, 目標就是打造程式員流暢的編輯環境。
 
這一外掛程式還能完成:

  • Statement oriented editing of C / C++ programs
  • Speed up writing new code considerably.
  • Write code and comments with a professional appearance from the beginning.
  • Use code snippets


接下來我們對這一外掛程式詳細介紹.

3 安裝外掛程式Step 1: 下載c.vim
$ cd /usr/src
$ wget http://www.vim.org/scripts/download_script.php?src_id=9679
Step 2: 安裝
$ mkdir ~/.vim
$ cd ~/.vim
$ unzip /usr/src/cvim.zip
Step 3: 啟用這一外掛程式
$ vim ~/.vimrc
filetype plugin on
8 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),
mehner@fh-swf.de
* Company: FH Südwestfalen, Iserlohn
*
* =================================================
*/


其中如果你要改變 AUTHOR 和 COMPANY的值, 要修改模板檔案 ~/.vim/c-support/templates/Templates

$ vim ~/.vim/c-support/templates/Templates
|AUTHOR| = geekstuff
|AUTHORREF| = gk
|EMAIL| = subscribe@geekstuff
|COMPANY| = thegeekstuff.com


現在編輯一個新檔案,看看你的作者和公司名稱改變了沒有。

$ vim myprogram.c
/*
* =================================================
*
* 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

Feature 3: 用"im 添加main函數

添加的效果如下: 

 

Fig 3: Insert C main function automatically

Feature 4: 用 "cfu 添加函數注釋
 

 

Fig 4: Insert C Function Header Automatically
 

Fig 5: Insert C Function Header Automatically

Feature 5:  用"cfr添加註釋架構

 

 

Fig 6: Insert a Frame Comment Automatically

Feature 6: 用"p<包含標頭檔

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/codesnippets
Makefile 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 檔案名稱,代碼就會自動插入了。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.