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

Re: Count character in line

Expand Messages
  • Benji Fisher
    ... e +/Count $VIMRUNTIME/macros/matchit.vim HTH --Benj Fisher
    Message 1 of 5 , Jan 1, 2003
      Klaus Bosau wrote:
      > Hi,
      >
      > I'd like to find out how often a certain character shows up in a line.
      > To achieve this I tried
      >
      > fun! s:N()
      > .s/x/&/ge
      > return substitute(v:statusmsg, '^\(.\).*', '\1', '')
      > endfun
      >
      > but this didn't work. Obviously v:statusmsg sometimes isn't set. How can
      > I ensure v:statusmsg is set? Or maybe there's another solution too...

      :help 'report'
      e +/Count $VIMRUNTIME/macros/matchit.vim

      HTH --Benj Fisher
    • Klaus Bosau
      ... Thanks a lot! I turned it in fun! s:N() let &report=0 .s/x/&/ge return substitute(v:statusmsg, ^ (. ).* , 1 , ) endfun but this seems to work properly
      Message 2 of 5 , Jan 1, 2003
        On Wed, 1 Jan 2003, Benji Fisher wrote:

        > :help 'report'
        > e +/Count $VIMRUNTIME/macros/matchit.vim

        Thanks a lot! I turned it in

        fun! s:N()
        let &report=0
        .s/x/&/ge
        return substitute(v:statusmsg, '^\(.\).*', '\1', '')
        endfun

        but this seems to work properly only if typed by hand. When put in a
        function body v:statusmsg still is not set reliably. The 'matchit'
        solution turned out to be quite similiar to the solution I already
        found, but due to that this seems to become a bit slow with large
        strings I'd actually prefer a working solution based on :s. I wished I'd
        know why v:statusmsg isn't set always...

        Thanks anyway!

        Klaus
      • Klaus Bosau
        ... Hi, and thanks! I already tried this, but obviously it sometimes isn t set by :s. I don t know why... Thanks, Klaus
        Message 3 of 5 , Jan 1, 2003
          On Wed, 1 Jan 2003, Antoine J. Mechelynck wrote:

          > you might set it yourself, e.g.
          >
          > function!...
          > let v:statusmsg = ""
          > .s/ etc.

          Hi,

          and thanks! I already tried this, but obviously it sometimes isn't set
          by :s. I don't know why...

          Thanks,

          Klaus
        Your message has been successfully submitted and would be delivered to recipients shortly.