先看一下最终效果(点击看大图):
下面我们一步一步的来配置:
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 let Tlist_Use_Right_Window=1 let Tlist_File_Fold_Auto_Close=1 3. 然后安装NERDTree 安装方法类似TagList, 就不再细说了. 简单的配置如下: map map 4. 配置Vim的智能补全, 即所谓的Omni Completion. fun! OmniComplete() let left = strpart(getline('.'), col('.') - 2, 1) if left =~ "^$" return "" elseif left =~ ' $' return "" else return "\\ endfun inoremap " 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 "\\ elseif left =~ ' $' return "\\ else return "\\ endfun inoremap 6. 其他的小配置: source $VIMRUNTIME/menu.vim set wildmenu set cpo-=< set wcm= map 最后配置好后为: vimrc # 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 90 91 92 93 94 95 96 97 98 99 100 101 set nocompatible set mouse=a syntax on filetype on filetype plugin on set autowrite set autoread 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 colo default " fn maping map map map map " TagList plugin map let Tlist_WinWidth = 30 let Tlist_Use_Right_Window=1 let Tlist_Use_SingleClick=1 map " vim menu source $VIMRUNTIME/menu.vim set wildmenu set cpo-=< set wcm= map map map map map " tab config map tn :tabnext map tp :tabprev map te :tabnew map tc :tabclose " clever tab completion fun! KeywordComplete() let left = strpart(getline('.'), col('.') - 2, 1) if left =~ "^$" return "\\ elseif left =~ ' $' return "\\ else return "\\ endfun inoremap fun! OmniComplete() let left = strpart(getline('.'), col('.') - 2, 1) if left =~ "^$" return "" elseif left =~ ' $' return "" else return "\\ endfun inoremap " 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 java set ofu=javacomplete#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 " turn on syntax highlighting on scala file autocmd FileType scala colo scala102 set t_Co=256