首先:找出乱码产生的原因。 一直以为是浏览器的原因,结果我在chrome,firefox,IE9里面都出现了乱码,所以浏览器的因素可以排除。为了验证我猜测是Gvim的原因,
我用记事本(note)简单写了一个php文件
复制代码 代码如下:
echo "你好";
echo "世界";
?>
复制代码 代码如下:
set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin
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 eq = '"'
else
let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
endif
else
let cmd = $VIMRUNTIME . '\diff'
endif
silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction
"设置默认背景色
colors desert
"设置不自动备份
set nobackup
"设置默认字体和大小
set guifont=Courier_New:h12:cANSI
set termencoding=gbk
set encoding=utf-8
"产生问题的原因
set fileencoding=chinese
set fileencodings=ucs-bom,utf-8,chinese
set langmenu=zh_CN.utf-8
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
language messages zh_cn.utf-8
language messages zh_cn.utf-8
syntax enable
syntax on
复制代码 代码如下:
colors desert
set nobackup
set guifont=Courier_New:h12:cANSI
"处理文本中显示乱码
set encoding=utf-8
set fileencodings=chinese
set fileencoding=chinese
"处理菜单及右键菜单乱码
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
"处理consle输出乱码
language messages zh_CN.utf-8
syntax enable
syntax on