GVIM亂碼問題的解決
Vim有四個跟字元編碼方式有關的選項,分別是:encoding、fileencoding、fileencodings、 termencoding (這些選項可能的取值請參考 Vim 線上協助 :help encoding-names),它們各自的意義:
* encoding: Vim 內部使用的字元編碼方式,包括 Vim 的 buffer (緩衝區)、菜單文本、訊息文本等。使用者手冊上建議只在 .vimrc 中改變它的值,事實上似乎也只有在 .vimrc 中改變它的值才有意義。
* fileencoding: Vim 中當前編輯的檔案的字元編碼方式,Vim 儲存檔案時也會將檔案儲存為這種字元編碼方式 (不管是否新檔案都如此)。
* fileencodings: Vim 啟動時會按照它所列出的字元編碼方式逐一探測即將開啟的檔案的字元編碼方式,並且將 fileencoding 設定為最終探測到的字元編碼方式。因此最好將 Unicode 編碼方式放到這個列表的最前面,將拉丁語系編碼方式 latin1 放到最後面。
* termencoding: Vim 所工作的終端 (或者 Windows 的 Console 視窗) 的字元編碼方式。這個選項在 Windows 下對我們常用的 GUI 模式的 gVim 無效,而對 Console 模式的 Vim 而言就是 Windows 控制台的字碼頁,並且通常我們不需要改變它。
由於 Unicode 能夠包含幾乎所有的語言的字元,Unicode的 UTF-8 編碼方式又是非常具有性價比的編碼方式,因此encoding 的值設定為utf-8。同時將encoding設定為utf-8時,Vim自動探測檔案的編碼方式會更準確。在中文 Windows裡編輯的檔案,為了兼顧與其他軟體的相容性,檔案編碼還是設定為GB2312/GBK比較合適,因此fileencoding建議設定為 chinese (chinese 是個別名,在Unix裡表示gb2312,在Windows裡表示cp936,也就是GBK的字碼頁)。
最終對於檔案中顯示亂碼、菜單亂碼、右鍵菜單亂碼以及Conlse輸出亂碼問題的解決方案,修改Vim編輯器所對應的設定檔_vimrc,添加如下配置:
"關閉上側工具列
set go-=T
"關閉右側捲軸
"set go-=r
"總是顯示標籤。0:不顯示;1:多於1個時顯示
set showtabline=2
"開啟行號
set number
"開啟自動縮排, 7.3以上版本已自動開啟
"set autoindent
"縮排寬度為4個字元
set shiftwidth=4
"tab寬度為4個字元
set tabstop=4
"編輯時將所有tab替換為空白格
set et
"按一次Backspace就刪除4個空格
set smarttab
"色彩配置
colo desert
"開啟文法高亮, 7.3版本已自動開啟
"syntax on
"字型設定
set guifont=courier_new:h10
"關閉相容模式
set nocompatible
"以下三行類比Windows操作,如Ctrl-C複製
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin
"不產生備份檔案,下面這句要寫在behave mswin下面,否則還是會產生備份,不知為何~
set nobackup
"GVIM內部編碼
set encoding=utf-8
"當前編輯的檔案編碼
set fileencoding=utf-8
"GVIM支援開啟的檔案編碼
set fileencodings=utf-8,gbk,gb2312,big5,latin1
"解決菜單及右鍵菜單亂碼
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
"解決consle輸出亂碼
language messages zh_CN.utf-8
"設定Linux終端為GVIM內部編碼,Windows下可不設定
let &termencoding=&encoding
"防止特殊符號無法正常顯示,如五角星等
set ambiwidth=double
set diffexpr=MyDiff()
function MyDiff()
let opt = '-a --binary '
if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
let arg1 = v:fname_in
if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
let arg2 = v:fname_new
if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
let arg3 = v:fname_out
if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
let eq = ''
if $VIMRUNTIME =~ ' '
if &sh =~ '\ let cmd = '""' . $VIMRUNTIME . '\diff"'
let eq = '"'
else
let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
endif
else
let cmd = $VIMRUNTIME . '\diff'
endif
silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction
"自動補全,7.3版本已自動開啟
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 php set omnifunc=phpcomplete#CompletePHP
autocmd FileType c set omnifunc=ccomplete#Complete
以上就介紹了VIM7.3設定(for Windows),包括了方面的內容,希望對PHP教程有興趣的朋友有所協助。