重裝 Ubuntu 之後要重新配置 Vim 環境,與其一步一步敲,不如寫成腳本一次跑完。以下是我的做法。
installvim.sh
[code]#!/bin/bash cd ~/ sudo apt-get -y update sudo apt-get -y install vim-gtk git mkdir -p ~/.vim/bundle cd ~/.vim/bundle git clone https://github.com/gmarik/Vundle.vim.git cd ~/Downloads wget https://prdownloads.sourceforge.net/ctags/ctags-5.8.tar.gz tar -zxvf ctags-5.8.tar.gz cd ctags-5.8 ./configure make sudo make install rm ctags-5.8.tar.gz cd .. rm -rf ctags-5.8 touch ~/.vimrc
.vimrc
[code]set nocompatible filetype off set rtp+=~/.vim/bundle/Vundle.vim call vundle#begin() Plugin 'gmarik/Vundle.vim' Plugin 'scrooloose/nerdtree' Plugin 'scrooloose/nerdcommenter' Plugin 'scrooloose/syntastic' Plugin 'jiangmiao/auto-pairs' "Plugin 'Valloric/YouCompleteMe' Plugin 'fatih/vim-go' "Plugin 'ctags.vim' Plugin 'taglist.vim' call vundle#end() filetype plugin indent on :colorscheme elflord set number set cursorline set tabstop=4 set softtabstop=4 set expandtab set shiftwidth=4 set smartindent set foldenable set foldmethod=syntax "nerdtree "autocmd vimenter * NERDTree map <C-b> :NERDTreeMirror<CR> map <C-b> :NERDTreeToggle<CR> "taglist let Tlist_Show_One_File=1 let Tlist_Exit_OnlyWindow=1 let Tlist_File_Fold_Auto_Close=1 let Tlist_Use_Right_Window=1 let Tlist_Show_Menu=1 let Tlist_Auto_Open=1
Step 1:建立名為 installvim.sh 的檔案,貼上上面的腳本。
Step 2:執行它(記得先 chmod +x installvim.sh)。
Step 3:把 .vimrc 放到家目錄。
Step 4:開啟 vim。
Step 5:在 vim 中執行 :PluginInstall 安裝外掛。
這套配置包含了 NERDTree 檔案樹、taglist 符號瀏覽、syntastic 語法檢查、auto-pairs 自動配對與 vim-go,日常寫 Go 或 C 都夠用。