Reply to message «Re: expand "(" doesn't work», 
sent 11:22:02 02 June 2011, Thursday
by Marcin Szamotulski:

> Hi,
> You can use:
>  getline(".")[col(".")-1]
> Best,
> Marcin
No, not this. You should use either
    matchstr(getline('.')[col('.')-1:], '^.')
or
    nr2char(char2nr(getline('.')[col('.')-1:]))
. First will capture character with composing characters if any, second will 
capture it without them, but will fail if next character is not a valid 
unicode. 
Your variant is not aware of multibyte characters and thus should not be used.

Original message:
> Hi,
> You can use:
>  getline(".")[col(".")-1]
> Best,
> Marcin
> 
> On 23:00 Wed 01 Jun     , sinbad wrote:
> > On Jun 1, 11:19 pm, Gary Johnson <[email protected]> wrote:
> > > On 2011-06-01, sinbad wrote:
> > > > hi,
> > > > 
> > > > doesn't expand("<cword>") work if the cursor is under "(".
> > > > it works for ")" though. any reason for this ?
> > > > i am running vim 7.0
> > > 
> > > I'm running 7.3.189 and it behaves differently.  I started vim as
> > > 
> > >     $ vim -N -u NONE
> > > 
> > > and used the line
> > > 
> > >     Now is the (time) for all good men
> > > 
> > > and the command
> > > 
> > >     :echo expand("<cword>")
> > > 
> > > with the following results.
> > > 
> > >      Cursor   Command
> > >     Location  Output
> > >     --------  -------
> > >        (       time
> > >        t       time
> > >        e       time
> > >        )       for
> > > 
> > > So, <cword> appears to refer to the word under the cursor or to
> > > the first word to the right if the cursor is not on a word.  This
> > > agrees with the documentation:
> > > 
> > >     :help cword
> > >     :help star
> > > 
> > > The behavior at 5.4m.23 was to expand <cword> to an empty string.
> > > (See $VIMRUNTIME/doc/version5.txt.)  I don't know when this changed
> > > to the current behavior or what the behavior was at 7.0.
> > > 
> > > Regards,
> > > Gary
> > 
> > so, how can one read any char under the cursor. is there an equivalent
> > <cchar>
> > 
> > 
> > thanks
> > sinbad

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to