Am 14.03.2010 18:15, schrieb Ingo Karkat:
> On 14-Mar-2010 17:49, Gregor Uhlenheuer wrote:
>> Hello,
>> I think the col() function does not work properly for lines with
>> apostrophe characters (`´).
>>
>> :echo col([line('.'), '$']) returns 6 on the line below:
>>
>> ´foo
>>
>> It should return 5 I think.
> 
> It depends on the encoding of the apostrophe character, as col() returns
> byte indices, not logical characters. You assume that the apostrophe
> uses only one byte, whereas it seems that it actually uses two bytes.
> 
> To investigate, check the 'encoding' and 'fileencoding' settings, and
> use the g8 command on the apostrophe character; it'll return the (UTF-8)
> byte sequence used to encode it. (This is a somewhat simplified
> explanation, it's a quite complex matter.)

Thanks for the input - I didn't know that.
> For many scripting uses, Vim's byte-orientation makes it difficult to
> properly deal with multi-byte strings, but there are ways to cope. For
> example, to count the number of characters, use
>     let len = strlen(substitute(str, ".", "x", "g"))

Since you nearly guessed my use of col() - I want to get the length of
the current line - thank you for the tip with the substitution. I
figured that using virtcol() is probably more appropriate for that
purpose.

Regards,
Gregor

-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Raspunde prin e-mail lui