• 2008-04-26

    打造自己的VIM - [VIM]

    版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
    http://memorise.blogbus.com/logs/19774767.html

    越来越习惯了VIM,趁着期中考结束,趁着刚安装完成ubuntu8.4,参考了wooin的教程,弄一个自己用着顺手的VIM,wooin教程中提到的很多功能对我来说不是很实用,我现在只是写一些很小的代码而已,所以只安装自己需要的功能。

    记录过程如下:

    1.ubuntu里面系统装的VIM是"精简版",所以要安装一个完整版本的:

    sudo apt-get install vim-full

    2. 安装中文帮助。将在http://vcd.gro.clinux.org下载的压缩包解压后,其中有个doc文件夹, 将其中内容全部复制到~/.vim/doc, 或者vim安装目录下的doc目录中, 在vim输入:help就能看到中文的帮助了。

    3. 设置自动缩进、行号等等东西

    直接写到~/.vimrc中

    4.设置语法高亮,新建~/.vim/syntax/c.vim,写入以下内容

    "========================================================
    " Highlight All Function
    "========================================================
    syn match cFunction "\<[a-zA-Z_][a-zA-Z_0-9]*\>[^()]*)("me=e-2
    syn match cFunction "\<[a-zA-Z_][a-zA-Z_0-9]*\>\s*("me=e-1
    hi cFunction gui=NONE guifg=#B5A1FF

    "========================================================
    " Highlight All Math Operator
    "========================================================
    " C math operators
    syn match cMathOperator display "[-+\*/%=]"
    " C pointer operators
    syn match cPointerOperator display "->\|\."
    " C logical operators - boolean results
    syn match cLogicalOperator display "[!<>]=\="
    syn match cLogicalOperator display "=="
    " C bit operators
    syn match cBinaryOperator display "\(&\||\|\^\|<<\|>>\)=\="
    syn match cBinaryOperator display "\~"
    syn match cBinaryOperatorError display "\~="
    " More C logical operators - highlight in preference to binary
    syn match cLogicalOperator display "&&\|||"
    syn match cLogicalOperatorError display "\(&&\|||\)="

    " Math Operator
    hi cMathOperator guifg=#3EFFE2
    hi cPointerOperator guifg=#3EFFE2
    hi cLogicalOperator guifg=#3EFFE2
    hi cBinaryOperator guifg=#3EFFE2
    hi cBinaryOperatorError guifg=#3EFFE2
    hi cLogicalOperator guifg=#3EFFE2
    hi cLogicalOperatorError guifg=#3EFFE2
    5. 安装ctags,去http://ctags.sourceforge.net下载最新的ctags,5.7版本的,然后安装
    tar -xzvf ctags-5.7.tar.gz
    cd ctags-5.7
    ./configure 
    make
    sudo make install
    安装完成。
    在任意一个有源代码的目录下执行ctags -R ,在该目录下就生成了tags文件
    进入vim,输入命令:set tags=./tags就能使用tag功能了。我直接把:set tags=./tags这句加到.vimrc中了
    免得每次都要输入命令。呵呵。 
     现在就可以使用C-]和C-T在代码中自如的跳动了。
    6.安装插件: TagList
    http://www.vim.org/scripts/script.php?script_id=273下载最新的TagList,解压到~/.vim
    然后在~/.vimrc中加入以下两句
    let Tlist_Show_One_File=1
    let Tlist_Exit_OnlyWindow=1
    然后打开任意一个有tags的源代码文件,敲入命令:Tlist,就可以看到tag了,很方便 
    7.安装插件: WinManager
    http://www.vim.org/scripts/script.php?script_id=95中下载winmanager.zip,然后解压到在 ~/.vim
    进入VIM后在普通模式下按下wm就可以看到各个窗口了,用c-w在各个窗口之间切换光标
    8.安装插件: MiniBufExplorer 
    下载http://www.vim.org/scripts/script.php?script_id=159,然后放到 ~/.vim/plugin
    当只编辑一个buffer的时候MiniBufExplorer派不上用场, 当打开第二个buffer的时候, MiniBufExplorer窗口就自动弹出来了
    在~/.vimrc中加入
    let g:miniBufExplMapCTabSwitchBufs = 1
    可以实现
    <C-Tab> 向前循环切换到每个buffer上,并在但前窗口打开
    <C-S-Tab> 向后循环切换到每个buffer上,并在但前窗口打开
    在~/.vimrc中加入
    let g:miniBufExplMapWindowNavVim = 1
    可以实现用<C-h,j,k,l>切换到上下左右的窗口中去,就像:
    C-w,h j k l    向"左,下,上,右"切换窗口.
     
     
    到此,VIM设置基本完成。其他更复杂的功能我目前还用不上,就不弄了。
    下面是我的vimrc
    syntax enable
    syntax on
    colorscheme advantage
    :set nu
    :set cindent shiftwidth=4
    :set ru
    set encoding=utf-8
    set ts=4
    set helplang=cn
    set tags=./tags

    let Tlist_Show_One_File=1
    let Tlist_Exit_OnlyWindow=1
    let g:winManagerWindowLayout='FileExplorer|TagList'
    nmap wm :WMToggle<cr>
    let g:miniBufExplMapCTabSwitchBufs = 1
    let g:miniBufExplMapWindowNavVim = 1
    if has("gui")
    set guifont=Courier\ 10\ Pitch\ 10
    endif
     上面所需要的安装文件都在这个包里了,免得以后再下载
    http://memorise.blogbus.com/files/12091419520.gz
     

    随机文章:

    劝勉联 2008-04-08
    无聊的假期 2008-02-11
    I‘m back 2008-02-01
    聚餐 2008-01-07

    收藏到:Del.icio.us




发表评论

您将收到博主的回复邮件
记住我