gvim 乱码

gvim 不能很好的检测 编码

 

所以需要一个好的fileencodings

 

有人推荐如下:

 

 

set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
 

 但是在遇到 ucs-16le 或者 ucs-16be的时候 (也就是一般所指 unicode)会出现问题,将之误判为utf-8,而且还会自做主张地在文件开头加上 utf-8 的 byte order mask (EF BB BF)

 

在其他网站看到有说法,最好将encoding设为 utf-8

如下:

 

 

 

if has("multi_byte")
  if &termencoding == ""
    let &termencoding = &encoding
  endif
  set encoding=utf-8
  set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
endif
 

 

尝试之后,的确能比较准确判断出 通常的那些 unicode 编码的文件

但是菜单却乱码了。而且gvim里的提示信息也乱码了。

 

最后按照gvim的帮助,最后把_vimrc 设置如下,就不会乱码了。缺点是不显示中文菜单

 

 

set nocompatible
set langmenu=none
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin
set nu!
set tabstop=4
colorscheme darkblue
set guifont=Courier_New:h14
if has("multi_byte")
  if &termencoding == ""
    let &termencoding = &encoding
  endif
  set encoding=utf-8
  if $LANG == "zh_CN"
	if &encoding == "utf-8"
		language message zh_CN.UTF-8
	elseif &encoding == "cp936"
		language message zh_CN.cp936
	endif
  endif
  set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
endif
let Tlist_Ctags_Cmd="C:\Program Files\emacs-23.3\bin\ctags.exe"
filetype on
if has("statusline")
 set statusline=%<%f\ %h%m%r%=%{\"[\".(&fenc==\"\"?&enc:&fenc).((exists(\"+bomb\")\ &&\ &bomb)?\",B\":\"\").\"]\ \"}%k\ %-14.(%l,%c%V%)\ %P
endif

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 =~ '\<cmd'
      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

 

*Attention :最好是写为这样 let Tlist_Ctags_Cmd="C:/Progra~1/Vim/vim73/ctags.exe"

用斜杠时在win7下总是报 failed to generate tags for 某文件

 

 

=========================================================================

以上所说,约等于没用,因为总是会有这样那样的错误,比如已经比较全面地解决了乱码,但是用make一编译代码,make 报的错误是中文就会出现<bb><b6>00<bd>这之类的乱码。现在找到的最完美解决方案如下:

 

在vim官网下有个地方,从来没有去注意过。

 

http://www.vim.org/download.php 写道
There are a few extra files:

iconv library libiconv
A library used for converting character sets. Put "iconv.dll" in the same directory as gvim.exe to be able to edit files in many encodings. You can find the dll file in the bin directory of the "libiconv-win32" archive.
newer intl library libintl
The included libintl.dll does not support encoding conversion. If you have installed the iconv library, as mentioned above, you can install a gettext library that uses it. Get "intl.dll" from the bin directory in the gettext-win32 archive and store it as "libintl.dll" in the same directory as gvim.exe, overwriting the file that may already be there.
 

就把第一个iconv下载下来,如说明中所说,将iconv.dll放到和gvim.exe的同一目录下。结果就能完美解析编码,也不用设来设去了。

你可能感兴趣的:(C++,c,C#,vim,emacs)