Windows gVim cannot read Chinese from clipboard created in Cygwin vim

已查看 111 次
跳至第一个未读帖子

Sean

未读,
2010年1月30日 14:01:032010/1/30
收件人 vim_use
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

已删除帖子

bill lam

未读,
2010年1月30日 19:55:452010/1/30
收件人 vim_use
sab, 30 Jan 2010, Sean skribis:

> Option #1, using cygwin putclip:
> ------------------------------
> :%y|call system('putclip', @@)
> ------------------------------
>
> option #2, using clip from Windows
> ---------------------------
> :%y|call system('clip', @@)
> ---------------------------

Window system clipboard use utf16 encoding. Did you test these two
program 'putclip' and 'clip' if they accept utf8? Or Did it work if
pasting to notepad?

--
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3

Sean

未读,
2010年1月30日 22:22:392010/1/30
收件人 vim_use
>> Or Did it work if pasting to notepad?

No. Pasting to notepad is even worse, as it all ended up with one
long line with the same garbled multi-bytes.

bill lam

未读,
2010年1月30日 23:13:142010/1/30
收件人 vim_use
sab, 30 Jan 2010, Sean skribis:
> >> Or Did it work if pasting to notepad?
>
> No. Pasting to notepad is even worse, as it all ended up with one
> long line with the same garbled multi-bytes.

I suggest you to make sure those clip program support unicode first
and translate encoding if necessary before feeding them data.

Sean

未读,
2010年1月31日 14:40:562010/1/31
收件人 vim_use
Further investigation shows

(1) from console vim, we can send kind of "binary" version of content
to clipboard by:
:%y|call system('/bin/putclip', @@)

(2) from gVim, we can "correct" the clipboard contents by:
:let @+=system('/bin/getclip')
(But we suffer a flash DOS box on the status line.)

(3) However, to "communicate" between console vim and gVim on the same
Windows box, it is easy to do write/read a temp file. CJK is never
garbled through "write/read" text file.

(4) It seems not possible to send readable CJK to Windows Clipboard
from console vim.

(5) Searching "clipboard" on this group showed many relating
discussions. One interesting one is the #13 "Console cygwin Vim
using win32 clipboard" on http://groups.google.com/group/vim_dev/web/vim-patches
It looks like that patch can make @+ register available for console
vim. If that is the case, the patch should be included to the official
distribution.


Thanks

Sean

回复全部
回复作者
转发
0 个新帖子