因工做需求,必須在終端下遠程下代碼,vim打開cpp/h文件,看到一連串的字母就傻了,根本沒法閱讀。javascript
後來才知道VIM這高大上的文本編輯器支持不少的功能,不少的功能。首先最基本的就是語法高亮配色css
1. 確認鏈接工具,這個很重要,由於工具的問題,找了老半天的緣由html
Putty,無需額外設置java
SecureCRT,選項 - 會話選項 - 終端 - 仿真 勾選「ANSI顏色」與「使用顏色方案」 python
![](http://static.javashuo.com/static/loading.gif)
2 確認VIM的安裝目錄,命令行輸入:whereis vim,輸出以下:git
![](http://static.javashuo.com/static/loading.gif)
ls -l /usr/share/vim/vim72/colors 查看系統支持哪些默認的配色方案,其中vim72是版本號,對應查找路勁便可vim
在當前用戶目錄下,新建".vimrc"文件,編輯一下內容:windows
"打開語法高亮
syntax on
"使用配色方案
colorscheme desert
"打開文件類型檢測功能
filetype on
"不一樣文件類型採用不一樣縮進
filetype indent on
"容許使用插件
filetype plugin on
filetype plugin indent on
"關閉vi模式
set nocp
"與windows共享剪貼板
set clipboard+=unnamed
"取消VI兼容,VI鍵盤模式不易用
set nocompatible
"顯示行號, 或set number
set nu
"歷史命令保存行數
set history=100
"當文件被外部改變時自動讀取
set autoread
"取消自動備份及產生swp文件
set nobackup
set nowb
set noswapfile
"容許使用鼠標點擊定位
set mouse=a
"容許區域選擇
set selection=exclusive
set selectmode=mouse,key
"高亮光標所在行
set cursorline
"取消光標閃爍
set novisualbell
"老是顯示狀態行
set laststatus=2
"狀態欄顯示當前執行的命令
set showcmd
"標尺功能,顯示當前光標所在行列號
set ruler
"設置命令行高度爲3
set cmdheight=3
"粘貼時保持格式
set paste
"高亮顯示匹配的括號
set showmatch
"在搜索的時候忽略大小寫
set ignorecase
"高亮被搜索的句子
set hlsearch
"在搜索時,輸入的詞句的逐字符高亮(相似firefox的搜索)
set incsearch
"繼承前一行的縮進方式,特別適用於多行註釋
set autoindent
"爲C程序提供自動縮進
set smartindent
"使用C樣式的縮進
set cindent
"製表符爲4
set tabstop=4
set expandtab
"%retab!
"統一縮進爲4
set softtabstop=4
set shiftwidth=4
"容許使用退格鍵,或set backspace=2
set backspace=eol,start,indent
set whichwrap+=<,>,h,l
"取消換行
set nowrap
"啓動的時候不顯示那個援助索馬里兒童的提示
set shortmess=atI
"在被分割的窗口間顯示空白,便於閱讀
set fillchars=vert:\ ,stl:\ ,stlnc:\
"光標移動到buffer的頂部和底部時保持3行距離, 或set so=3
set scrolloff=3
"設定默認解碼
set fenc=utf-8
set fencs=utf-8,usc-bom,euc-jp,gb18030,gbk,gb2312,cp936
"設定字體
set guifont=Courier_New:h11:cANSI
set guifontwide=新宋體:h11:cGB2312
"設定編碼
set enc=utf-8
set fileencodings=ucs-bom,utf-8,chinese
set langmenu=zh_CN.UTF-8
language message zh_CN.UTF-8
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
"自動補全
filetype plugin indent on
set completeopt=longest,menu
"自動補全命令時候使用菜單式匹配列表
set wildmenu
autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType java set omnifunc=javacomplete#Complet
保存後,用VIM打開C++文件就有顏色啦。如:ruby
![](http://static.javashuo.com/static/loading.gif)
默認採用desert配色,若是須要擴展,可自行到git下載更加全面的配色方案,只需將xxx.vim文件複製到目錄/usr/share/vim/vim72/colors編輯器
編輯.vimrc文件設置,「colorscheme xxx」 便可