python3 and multibyte strings

22 views
Skip to first unread message

Stanislav Kondratyev

unread,
May 1, 2012, 3:55:07 PM5/1/12
to vim_multibyte
Hello!

I was experimenting with the python3 interface and I stumbled upon the
following phenomenon. Suppose the cursor is in the string
абвгдеёжзийклмнопрстуфхцчшщъыьэюя
in a utf-8 encoded file. I run the following commands:
:py3 import vim
:py3 vim.current.line = vim.current.line
Surprisingly last 16½ of 33 characters disappear.

The same effect can be produced e. g. with
:py3 l = vim.current.line
:py3 vim.current.line = l
However, the string l can be correctly printed and sent to vim via
vim.command and setline. Hence I conclude that the transition from vim
to python does not cause any loss of information. On the contrary,
when the string is being passed from python to vim, vim (or python?)
calculates that it is 33 ‘units’ long and copies 33 *bytes*.

I’m running vim 7.3 on Windows 7.

I’d like to find out whether this is a common effect and whether there
exists an elegant way of changing multibyte strings from python3.

Any help is appreciated. :)

John Beckett

unread,
May 2, 2012, 3:22:07 AM5/2/12
to vim_mu...@googlegroups.com
Stanislav Kondratyev wrote:
> I run the following commands:
> :py3 import vim
> :py3 vim.current.line = vim.current.line
> Surprisingly last 16½ of 33 characters disappear.

In principle vim_multibyte is the correct mailing list, but in
practice it is not used much any more.

I think you should repost in vim_dev because it sounds like a
bug that should be addressed there (or vim_use would do).

I do not have Python 3 installed, but do have 2.7. That version
works fine performing your test. I also did:

:py vim.current.line = vim.current.line + ' hello'

which correctly appended "hello" to the 33 characters.

Please try a simpler test case. If you can show a problem with
the following line, just mention that.

aàáâãä

In case my mail system corrupts the above text, you can
reproduce it in Vim by executing the following two commands:

:let s = "a\u00e0\u00e1\u00e2\u00e3\u00e4"
:put =s

John

Stanislav Kondratyev

unread,
May 5, 2012, 6:57:50 AM5/5/12
to vim_multibyte
Thanks, John! I'm going to repost that in the proper place.

Stanislav.
Reply all
Reply to author
Forward
0 new messages