"Cyril Slobin" <[EMAIL PROTECTED]> writes:

> On 11/24/08, Jürgen Krämer <[EMAIL PROTECTED]> wrote:
>
>> > b) How to get char under cursor. Sure, yanking works. But maybe you
>> >    don't want to change the registers.
>> >   answer:
>> >     getline('.')[col('.')-1]
>>
>>
>> you cannot use this getline()-expression reliably if encoding is
>> set to utf8 and your line contains non-ASCII characters, because
>> getline()[i] only returns *one* byte of a possible multi-byte
>> sequence,
>
> In my scripts I use this construction -- seems ugly, but works:
>
> function <SID>Process()
>   let [buf, row, col, off] = getpos(".")
>   let [whole, before, old, after; rest] =
>   \ matchlist(getline("."), printf('^\(.\{-}\)\(.\?\)\%%%dc\(.*\)$', col))
>   " old now contains the char under cursor, in the following code
>   " we are replacing it with something else
>   let new = SomethingElse();
>   let col = col - strlen(old) + strlen(new)
>   call setline(".", before . new . after)
>   call setpos(".", [buf, row, col, off])
>   return ""
> endfunction
>
> The regexp seems complex because it should process even the corner
> cases, such the cursor after the last character in insert mode.

Thanks, I have bookmarked it, thought it's too complex for me now, I
hope it would be useful when my vim skill improves to a relative higher
level in future.  :)

-- 
Regards,

  anhnmncb
 gpg key: 44A31344

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

Reply via email to