Loading ...
Sorry, an error occurred while loading the content.
 

Re: expand "(" doesn't work

Expand Messages
  • Marcin Szamotulski
    Hi, You can use: getline( . )[col( . )-1] Best, Marcin ... -- You received this message from the vim_use maillist. Do not top-post! Type your reply below the
    Message 1 of 5 , Jun 2 12:22 AM
      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 <garyj...@...> 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
      >
      > --
      > You received this message from the "vim_use" 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

      --
      You received this message from the "vim_use" 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
    • ZyX
      Reply to message «Re: expand ( doesn t work», sent 11:22:02 02 June 2011, Thursday ... No, not this. You should use either
      Message 2 of 5 , Jun 2 2:08 AM
        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 <garyj...@...> 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
      Your message has been successfully submitted and would be delivered to recipients shortly.