Hello Yongwei, try FencView.vim http://www.vim.org/scripts/script.php?script_id=1708
Saturday, February 24, 2007, 11:31:40 PM, you wrote: >?The Vim option 'fileencodings' has some limitations: e.g., it cannot >?autodetect GBK and Big5 files at the same time. That was my first >?motivation to develop a solution for it. It has two parts: a generic >?C++ program to decide the encoding of a file, and a Vim plugin to use >?this program. >?The program tellenc tells the encoding a file according to the following: >?- Presence of any BOM character: The Unicode encoding of the BOM >?- Absence of non-ASCII characters: ascii >?- UTF-8 decodable: utf-8 >?- Uneven distribution of NULs in odd and even positions of the file: >utf-16(le) >?- Strange characters and not a Unicode encoding decided above: binary >?- Most high character followed by a low character: latin1 >?- Frequency analysis of DBCS characters: gbk (gb2312) and big5 >?- Otherwise: unknown >?I believe the frequency analysis can be applied at least to Japanese >?and Korean, but I do not know the languages and have no data. If you >?are Japanese or Korean, you may want to use "tellenc -v" on your text >?files and come up with some useful data to put into the program. >?Patches are welcome, though I admit it is not well commented or >?documented now: given enough interest, I will refactor and enhance the >?program as need be. >?This script MultiEnc.vim does these things to decide the encoding of a file: >?- If a file has a modeline fileencoding=..., it will be used as the >?encoding to open the file. >?- If a file is an HTML file, and it has the encoding specified with a >?HTTP-EQUIV meta tag, it will be used as the encoding to open the file. >?The file pattern of HTML files can be customized by the global >?variable multienc_html_patterns. >?- If a file cannot be decided by the steps above, tellenc may be used >?to decide its encoding. This includes HTML files without a suitable >?HTTP-EQUIV meta tag, and additional files can be detected with the >?global variable multienc_auto_patterns. >?- A file can be manually autodetected with the command >?EditAutoEncoding (without a file name for the current buffer, or with >?a file name to edit a new file). >?- The autodetection may be overridden with the command >?EditManualEncoding ("e ++enc=" may not work in some cases now). >?The program used to tell the encoding of a file is "tellenc" by >?default. It can also be changed with the environment variable >?MULTIENC_TELLENC. A simplistic _vimrc (for Windows) may be like: >?---------------------------------------------------------------------- >?" Legacy encoding is the system default encoding >?let g:legacy_encoding=&encoding >?source $VIMRUNTIME/vimrc_example.vim >?source $VIMRUNTIME/mswin.vim >?if has('gui_running') >? set encoding=utf-8 >?else >? if &termencoding != '' && &termencoding != &encoding >? let &encoding=&termencoding >? let &fileencodings='ucs-bom,utf-8,' . &encoding >? endif >?endif >?" Set default file encoding(s) to the legacy encoding >?exec 'set fileencoding=' . g:legacy_encoding >?let &fileencodings=substitute >? \(&fileencodings, '\<default\>', g:legacy_encoding, '') >?" File patterns of files for automatic encoding detection >?let multienc_auto_patterns='*.txt,*.tex' >?let multienc_html_patterns='*.htm{l\=},*.asp' >?---------------------------------------------------------------------- >?It is currently only tested on Windows. While I believe it should work >?on other platforms as well, there might be things I missed. Patches >?and bug reports are welcome. >?MultiEnc.vim is available at: >? http://www.vim.org/scripts/script.php?script_id=1806 >?Tellenc is available at: >? http://wyw.dcweb.cn/download.asp?path=&file=tellenc.zip >?Thank Tony and Benji for encouraging me to make it into a separate script. >?A question for Bram: Any way to extend Vim with DLLs? Starting an >?external program with system(...) is sometimes slow on Windows, and >?there will be a flashing command window, which is visible in some >?cases, esp. on slower machines. >?Best regards, >?Yongwei -- Best regards, mbbill mailto:[EMAIL PROTECTED]