亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

vim 配置過程記錄(一)

系統 1919 0

一:配置 vim 的顏色方案

配置顏色方案,下載插件ColorSamplerPack.zip,將其解壓縮到 .vim 文件夾下,如果沒有該文件夾,則自己創建一個。在 .vimrc 文件中添加下面一行配置:

colorscheme fruity

其中 fruity 是一個顏色主題的名字,當然也可以選用別的主題(筆者在嘗試多個主題后選擇了 fruity ),ColorSamplerPack.zip 的頁面上有鏈接指向各個主題的預覽。

但是,這里的許多主題只適用于 iGvim(包括fruity在內),所以需要另外的插件來允許這些顏色主題工作在終端里。需要的插件是 CSApprox.zip,下載該插件,將其解壓到 .vim 中,更新 vim 的幫助文件(也就是將關于該插件的幫助內容添加到 vim 的幫助文件中,命令如下:

vim -c 'helptags ~/.vim/doc'

完成之后,啟動 vim 出現如下錯誤信息: “ CSApprox needs gui support - not loading.? See :help |csapprox-+gui| for possible workarounds. ” 。根據提示,查閱幫助文件的相關章節,找到如下信息:

If CSApprox is being used to adjust a scheme's colors transparently, then the terminal "vim" binary that is being run must be built with GUI support (see |csapprox-limitations| for an explanation).
Unfortunately, several Linux distributions only include GUI support in their "gvim" binary, and not in their "vim" binary.? You can check if GUI support is available with the following command:
??? :echo has('gui')
If that prints 0, the first thing to try would be searching for a larger vim package provided by your distribution, like "vim-enhanced" on RedHat/CentOS or "vim-gtk" or "vim-gnome" on Debian/Ubuntu.

根據提示,在筆者的系統(ubuntu 11.10)需要安裝 vim-gtk 或者 vim-gnome 軟件包,輸入如下命令進行安裝:

sudo apt-get install vim-gtk

安裝完成之后,再次執行 vim 又出現如下錯誤信息:“ CSApprox skipped; terminal only has 8 colors, not 88/256. Try checking :help csapprox-terminal for workarounds ”。根據提示,查閱幫助文件相關章節,找到如下信息:

many modern terminals support 88 or 256 colors, but most of these default to setting $TERM to something generic (usually "xterm").? Since Vim uses the value of the "colors" attribute for the current $TERM in terminfo to figure out the number of colors used internally as 't_Co', this plugin will either need for 't_Co' to be set to 88 or 256 in |vimrc|, or for $TERM to be set to something? that implies high color support.? Possible choices include "xterm-256color" for 256 color support and "rxvt-unicode" for 88 color support.

根據上述提示,可以有兩種解決方案,一是在 .vimrc 文件中將 t_Co 設置成 88 或者 256,另外一種是將 $TERM 設置成別的值來支持更多的顏色。這里,筆者采用第一種方法,在 .vimrc 文件中添加下面一行配置:

set t_Co=256

再次運行 vim ,沒有輸出錯誤信息,vim 的顏色主題也變成我們所設置的。

二:安裝 cvim 插件

下載插件 cvim.zip,將其解壓縮到 .vim 文件夾下面,然后用上面提到的命令將 cvim 的幫助文件添加到 vim 的幫助文件中。 如果要讀取該幫助文件,在 vim 中執行下面命令

:h csupport

以熟悉插件功能,并驗證 cvim 的幫助文 檔已經導入 。值得一提的是,在 cvim 插件的主頁上有 cvim 快捷鍵的 pdf 文檔,可以作為參考。

cvim 插件會在我們利用 vim 新建 .c 或者 .cpp為后綴的文件時,自動在文件開始出添加一些信息,這些信息可以在 ~/.vim/c-support/templates 文件夾中的 各個文件中進行修改,在 Template 文件中,輸入自己的名字,郵箱等信息,保存。再利用 vim 來創建 .c 或者 .cpp 的文件時,這些信息就會被自動添加到新文件的開始處。

---------------------------------------------------------------------------------------------

2012-06-06 添加

?

在使用cvim的時候,一直沒有注意到一個問題,裝上cvim插件后,無論是創建 *.c 還是 *.cpp 文件,文件頭部分總是一樣,如下:

      /*

 * ===========================================================================

 *

 *       Filename:  test.c

 *

 *    Description:  

 *

 *        Version:  1.0

 *        Created:  06/06/2012 11:09:29 AM

 *       Revision:  none

 *       Compiler:  gcc

 *

 *         Author:  Long Wen (longcpp), longcpp9@gmail.com

 *   Organization:  SDU

 *

 * ===========================================================================

 */


    

理想的情況應該是對 *.cpp文件,其中Compiler部分,對應的應該是 g++。相同的問題還出現在,利用cvim的快捷鍵插入代碼時。我將c.idioms.template中main主函數部分修改如下(對默認的格式不大習慣,大家也可以修改別的部分):

      == idioms.main ==

#include	<stdio.h>

#include	<stdlib.h>



int main(int argc, char *argv[])

{<CURSOR>

<SPLIT> return EXIT_SUCCESS;

}/* ----------  end of function main  ---------- */


    

將cpp.idioms.template中main主函數部分修改如下:

      == idioms.main ==

#include	<iostream>

#include	<cstdlib>

#include	<vector>

#include	<string>

#include	<algorithm>



using namespace std;



int main(int argc, char *argv[])

{<CURSOR>

<SPLIT>	return EXIT_SUCCESS;

}// ----------  end of function main  ----------


    

?理想的情況,就應該是編輯 *.c 文件時和 *.cpp 文件時,\im 插入代碼應該是不同的,而事實是不管是什么文件,插入的總是c.idioms.template中的代碼。

解決的問題的關鍵,就在Templates($HOME/.vim/c-support/tempaltes)中,Templates中有如下語句:

      $ =============================================================

$ ========== USER MACROS ======================================

$ =============================================================

$

|AUTHOR|    = Long Wen

|AUTHORREF| = longcpp

|EMAIL|     = longcpp9@gmail.com

|COMPANY|   = SDU

|COPYRIGHT| = Copyright (c) |YEAR|, |AUTHOR|

|STYLE|     = default

$

$ =============================================================

$ ========== FILE INCLUDES ====================================

$ =============================================================

$

|includefile| = c.comments.template

|includefile| = c.cpp.template

|includefile| = c.idioms.template

|includefile| = c.preprocessor.template

|includefile| = c.statements.template

$

== IF |STYLE| IS CPP ==

|includefile| = cpp.comments.template

|includefile| = cpp.cpp.template

|includefile| = cpp.idioms.template

|includefile| = cpp.preprocessor.template

|includefile| = cpp.statements.template

== ENDIF ==

$


    

查閱幫助文檔就知道了,cvim根據STYLE的值來有選擇性包含不同的模板(通過IF,IS,ENDIF關鍵詞),而默認情況下,STYLE的值為default,此時,僅僅包含不在IF和ENDIF之間的文檔。這樣的話,上述問題就明白了,因為不論我們編輯什么文件,包含的永遠都是 c.comments.template 等為c代碼預置的模板。可以簡單的將STYLE的值改為CPP,但是這樣的話,又僅包含 cpp.comments.template 等為cpp代碼預置的模板。所以,我們真正需要的是,能夠根據所編輯文件的擴展名,來動態指定STYLE。

幸運的是,在幫助文檔中,找到了解決方法,就是在 .vimrc 文件中添加如下配置語句:

let g:C_Styles = { '*.c,*.h' : 'default', '*.cc,*.cpp,*.hh' : 'CPP' }

具體原因的解釋如下:(csupport幫助文檔)

      ==============================================================================

5.5  BINDING A STYLE TO A FILE EXTENSION             *csupport-templates-bind*

==============================================================================



You can bind the existing styles to one or more filename extensions. To do so

assign a Dictionary to the global variable g:C_Styles in '~/.vimrc' :



let g:C_Styles = { '*.c,*.h' : 'default', '*.cc,*.cpp,*.hh' : 'CPP' }



A Dictionary is created with a comma separated list of entries in curly

braces.  Each entry has a key and a value, separated by a colon.  Each key can

only appear once. The keys are themselves a comma separated list of filename

pattern. The values are existing styles defined in the template files.

The given style will be set automatically when switching to a buffer or

opening a new buffer with the associated filename pattern and supersedes the

macro *|STYLE|* .


    

接下來就是修改Templates($HOME/.vim/c-support/tempaltes),修改后的部分內容如下:

      |COPYRIGHT| = Copyright (c) |YEAR|, |AUTHOR|

|STYLE|     = CPP

$

$ =============================================================

$ ========== FILE INCLUDES ====================================

$ =============================================================

$

==  IF |STYLE| IS C ==

|includefile| = c.comments.template

|includefile| = c.cpp.template

|includefile| = c.idioms.template

|includefile| = c.preprocessor.template

|includefile| = c.statements.template

== ENDIF ==

$

== IF |STYLE| IS CPP ==

|includefile| = cpp.comments.template

|includefile| = cpp.cpp.template

|includefile| = cpp.idioms.template

|includefile| = cpp.preprocessor.template

|includefile| = cpp.statements.template

== ENDIF ==

$


    

?因為我經常寫的是CPP代碼,所以將STYLE的初值設定為CPP

?

2012-06-06添加結束

---------------------------------------------------------------------------------------------

三:自定義狀態行

set laststatus=2??? "總是顯示狀態行,狀態欄占兩行
"自定義狀態行
set statusline=\%F%m%r%h%w[%L]\ [%{&ff}]\ [TYPE=%Y]\ [POS=%04l,%04v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}
"%F??? ???   當前文件絕對路徑??? ????? %m??? ???   已修改標志
"%r??? ???   只讀標志??? ??? ??? ???   %h??? ???    幫助文件標志
"%w??? ???  ? 預覽標志??? ??? ??? ???   %L??? ???    文件總行數
"%{&ff}???  文件格式??? ??? ??? ???   %y???     ?使用的語法高亮器
"%p%%???  當前光標位置百分比??? ?? %04l???    當前行數
"%04v???   當前列數??? ??? ??? ???   strftime   為時間值

四:代碼折疊

" 折疊方法
" manual 手工折疊
" indent 使用縮進表示折疊
" expr 使用表達式定義折疊
" syntax 使用語法定義折疊
" diff 對沒有更改的文本進行折疊
" marker 使用標記進行折疊, 默認標記是 {{{ 和 }}}
set foldenable
set foldmethod=indent
""set foldclose=all
set foldcolumn=4??? "在左側顯示折疊的層次
highlight FoldColumn guibg=#454343? guifg=Yellow "設置前景色與背景色

五:括號與引號的自動補全

"自動括號和引號補全
:inoremap ( ()<ESC>i
:inoremap ) <c-r>=ClosePair(')')<CR>
:inoremap { {}<ESC>i
:inoremap } <c-r>=ClosePair('}')<CR>
:inoremap [ []<ESC>i
:inoremap ] <c-r>=ClosePair(']')<CR>
:inoremap < <><ESC>i
:inoremap > <c-r>=ClosePair('>')<CR>
:inoremap " ""<ESC>i
:inoremap ' ''<ESC>i

function ClosePair(char)
??? if getline('.')[col('.') - 1] == a:char
??????? return "\<Right>"
??? else
??????? return a:char
??? endif
endf

六:設置備份

set backup??? ??? ??? ??? ??? ??? ??? "keep a back up file
set backupdir=$HOME/.vim.backupdir??? "central backup directory(has to be created)

注意,添加這條配置語句,需要在用戶家目錄下建立文件夾 .vim.backdir

七:安裝 Taglist 插件

首先需要安裝 ctags 工具,用如下命令:

apt-get install exuberant-ctags

下載 taglist 插件,然后將其解壓縮的 .vim 文件夾下。更新 vim 的幫助文件。在 .vimrc 文件中添加如下配置語句(其中,以引號開頭的是被注釋掉的,可以根據自己偏好來設定):

"let Tlist_Auto_Open = 1???????????? "啟動vim時,自動打開taglist窗口
let Tlist_Exit_OnlyWindow = 1?????? "如果只有taglist窗口打開,則退出vim
"let Tlist_Use_SingleClick = 1?????? "通過鼠標單擊在tag之間跳轉(不是雙擊)
let Tlist_Compact_Format = 1??????? "緊湊的打印模式,盡可能多的輸出tag
let Tlist_WinWidth = 20???????????? "taglist窗口的默認寬度
let Tlist_Enable_Fold_Column = 0??? "disable column fold

在 vim 里面,可以用命令 :TlistToggle 來打開或者關閉 taglist 窗口,用 :help taglist 可以查看相應的幫助文檔

?

vim 配置過程記錄(一)


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 4虎影院午夜在线观看 | 黄色录像网址 | 精品日本久久久久久久久久 | 国产黄色一级大片 | 日本精品在线观看视频 | 黄色成人影院 | 在线观看视频色 | 日本中文字幕在线播放 | 亚洲a在线视频 | 激情综合色综合啪啪开心 | 亚洲一区播放 | 毛片永久新网址首页 | 日韩一区二区久久久久久 | 日日日日人人人夜夜夜2017 | 亚洲精品一区二区中文 | 视频一区久久 | 激情综合在线观看 | 国产亚洲精品久久久久久午夜 | 牛牛影视在线入口 | 天天插天天射天天操 | 成人久久18网站 | 操操操天天操 | 欧美日韩1区 | 国内精品久久久久久影院8f | 亚洲无吗在线视频 | 精品久久洲久久久久护士免费 | 欧洲色综合精品 | 69成人做爰视频在线观看 | 天然素人在线观看 | 不卡的在线视频免费观看 | 久久久四虎成人永久免费网站 | 4虎永免费最新永久免费地址 | 牛牛精品| 亚洲精品乱码久久久久久中文字幕 | 日日摸夜夜 | 美女一级大黄录像一片 | 国产亚洲综合视频 | 欧美日韩国产一区二区三区播放 | 天天干夜夜曰 | 性做久久久久免费看 | 免费看一级毛片欧美 |