Saturday, January 30, 2010

Windows gVim cannot read Chinese from clipboard created in Cygwin vim

On Windows, I have one single vimrc for both gVim and cygwin vim.
It works great, and both can input Chinese using VimIM plugin without
touching |+multi_byte_ime|.

The key vimrc setting to display Chinese are:

set enc=utf8 gfn=Courier_New:h12:w7 fencs=ucs-bom,utf8,chinese
set
gfw=NSimSun-18030,GulimChe,GungsuhChe,FangSong,MS_Mincho,SimHei

Now, open console vim, I can type Chinese at will: (correct Chinese
below)

沧海月明珠有泪
蓝田日暖玉生烟

The problem came in when I wanted to put the content to Windows system
clipboard.

Because console vim does not support @+ or @" register, I have to
use external programs. But that is not an issue as making system()
calls from console vim is a pleasant (sorry for gVim.exe).

Option #1, using cygwin putclip:
------------------------------
:%y|call system('putclip', @@)
------------------------------

option #2, using clip from Windows
---------------------------
:%y|call system('clip', @@)
---------------------------

Both above options worked in the way that the content (14 Chinese
characters) was put successfully in Windows clipboard.

However, when I opened gVim, and pasted from clipbard (:put *),
I found garbled characters:

From option #1, I got the following mess:
-------------------------------------
æ²§æµ·æœˆæ˜Žç  æœ‰æ³ª
è" ç"°æ—¥æš–玉ç"ŸçƒŸ
-------------------------------------

From option #2, I got the following mess:
-------------------------------------
沧海月明珠有泪
蓝田日暖玉生烟
-------------------------------------

Further investigation shows that the content in the Windows clipboard
is not lost.
I could get the original Chinese by the following steps using gVim:

(1) gVim vimrc
set enc=ansi gfn=Courier_New:h12:w7 fencs=ansi
(2) gVim
(3) :put *
(4) :wq myfile
(5) gVim vimrc
set enc=utf8 gfn=Courier_New:h12:w7 fencs=ucs-bom,utf8,chinese
(6) gVim
(7) :r myfile

I also searched wikia, but found nothing dealing with multi-bytes:
http://vim.wikia.com/wiki/Using_the_Windows_clipboard_in_Cygwin_Vim

It looks like the issue is ++enc=utf8 cannot "translate"/"detect"
clipboard content?

Any thing do I missed?


Thanks

Sean

--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment