Zhaojun WU wrote:
Hi, all,

Is it possible to print the hex value of the cp936-coded Chinese
character under the current cursor, just like "ga" for the ASCII char.

I found that "g8" can print the correct hex value of UTF8-encoded
Chinese character in a openning UTF-8 encoded file.

But, for a cp936 (or GBK) encoded file, although gvim can auto-detect
it as cp936 and open it successfully, I still cannot figure out how to
get the hex value of a Chinese character.

In this case (I mean opening a cp936 file in GVIM), I tried "ga" and
"g8" for fun. "ga" cannot work as I expected, "g8" continues to print
the hex value of the Chinese character's corresponding UTF8 encode,
not the cp936 one that I need. I think the result of "g8" is because
of gvim's implementation that it treats all the characters' encoding
as UTF-8 internally. Am I right?

Again, is it possible for me to print the hex value of a cp936-encoded
Chinese char?

BTW, the encoding related settings in my .vimrc are:

set encoding=utf-8
set fileencodings=ucs-bom,utf-8,cp936,latin1

Thanks,

":set encoding=utf-8" tells Vim to use UTF-8 internally to represent all file data. This is usually OK; but the replies to ga and g8 will be based on what is in memory, i.e., the UTF-8 equivalents of the character at the cursor.

If you want to examine the actual cp936 data at a given point in the file, I can think of two methods:


Method I. Convert to hex display.

This can be done by means of the "xxd" utility, which is normally distributed together with Vim, as follows:

        xxd < filename.txt > filename.hex

"filename.hex", which is a text file, will then contain the hex values of all bytes in the file, with at left the offset within the file in hex, and at right the "text" as 16 ASCII characters per line, with unprintable bytes replaced by dots.


Method II. Use cp936 as internal encoding. (Untested)

This means setting 'encoding' to cp936 rather than utf-8. Beware! You should have no file in any other multibyte encoding in the same instance of Vim, not even in a different window, not even hidden-but-modified. Better start afresh with a new run of gvim, edit only that single file, use ga as necessary, and close Vim when done.


Best regards,
Tony.
--
It's a damn poor mind that can only think of one way to spell a word.
                -- Andrew Jackson

Reply via email to