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.

-- 
http://slobin.pp.ru/ `When I use a word,' Humpty Dumpty said,
<[EMAIL PROTECTED]> `it means just what I choose it to mean'

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

Reply via email to