[教程] 把Vim配置成IDE - [教程]

[教程] 把Vim配置成IDE - [教程]

先看一下最終效果(點擊看大圖):

下面我們一步一步的來配置:

1. 基本配置

    set nocompatible
    set mouse=a
    syntax on
    filetype on
    set autowrite
    set number
    set showcmd
    set lcs=tab:>-,trail:-
    set list
    set showmode
    set title
    set tabstop=4
    set ruler
    set encoding=utf-8
    set fileencoding=utf-8
    set nobackup
    set autoindent
    set smartindent
    set expandtab
    set shiftwidth=4
    set smarttab
    set fdm=indent
    set fdc=4
    set nowrap
    set hlsearch
    set incsearch

 

2. 然後是安裝TagList插件

    在 這裏 可以找到TagList的介紹和下載地址, 安裝vim插件的方法都一樣, 就是把壓縮包下載下來, 解壓縮, 一般會得到一個plugin目錄和doc目錄. 在*nix系統(比如Linux或Mac OS X)中, 只要把這兩個文件夾下的文件分別放到~/.vim/plugin和~/.vim/doc下面就行了.

    plugin目錄下的東西, vim在下次啓動時會自動加載, 而那個doc目錄下的文件是個幫助文檔, 需要用vim打開這個幫助文檔, 然後在命令模式下輸入 :helptags . (別漏了最後的句點)

    TagList的簡單配置如下:

    map <F3> :Tlist<CR>
    let Tlist_Use_Right_Window=1
    let Tlist_File_Fold_Auto_Close=1

3. 然後安裝NERDTree

    安裝方法類似TagList, 就不再細說了.

    簡單的配置如下:

    map <F1> :NERDTreeMirror<CR>
    map <F2> :NERDTreeToggle<CR>

 4. 配置Vim的智能補全, 即所謂的Omni Completion.

    fun! OmniComplete()
    let left = strpart(getline('.'), col('.') - 2, 1)
    if left =~ "^$"
        return ""
    elseif left =~ ' $'
        return ""
    else
        return "/<C-x>/<C-o>"
    endfun
    inoremap <silent> <S-Tab> <C-R>=OmniComplete()<CR>

    " turn on Omni completion
    autocmd FileType c set ofu=ccomplete#Complete
    autocmd FileType php set ofu=phpcomplete#CompletePHP
    autocmd FileType python set ofu=pythoncomplete#Complete
    autocmd FileType javascript set ofu=javascriptcomplete#CompleteJS
    autocmd FileType html set ofu=htmlcomplete#CompleteTags
    autocmd FileType css set ofu=csscomplete#CompleteCSS
    autocmd FileType xml set ofu=xmlcomplete#CompleteTags

5. 配合ctags, vim可以從一個函數調用跳轉到其函數定義(快捷鍵是CTRL+]), ctags的用法很簡單, 一般來說, 只要在項目的根目錄運行 ctags -R . 就行了. vim在啓動時, 會自動尋找當前目錄下的tags文件, 如果有就會加載, 當然, 也可以告訴vim去哪裏找tags文件, 配置如下:

    set tags=./tags,~/my/project/tags

還可以配置Tab鍵來智能補全tags:

    fun! KeywordComplete()
    let left = strpart(getline('.'), col('.') - 2, 1)
    if left =~ "^$"
        return "/<Tab>"
    elseif left =~ ' $'
        return "/<Tab>"
    else
        return "/<C-N>"
    endfun
    inoremap <silent> <Tab> <C-R>=KeywordComplete()<CR>

6. 其他的小配置:

    source $VIMRUNTIME/menu.vim
    set wildmenu
    set cpo-=<
    set wcm=<C-Z>
    map <F6> :emenu <C-Z>

到目前爲止, 我們的vim就相當好用了, 最終的配置文件在這裏: http://gist.github.com/70732

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章