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

Wrong characters count when using utf-8

Expand Messages
  • Valery Kondakoff
    Hello, Bram! Thursday, May 29, 2003, you wrote to me: BM If you want a function you could use something like: BM strlen(substitute(getline( . )),
    Message 1 of 6 , May 29, 2003
    • 0 Attachment
      Hello, Bram!

      Thursday, May 29, 2003, you wrote to me:


      BM> If you want a function you could use something like:
      BM> strlen(substitute(getline(".")), ".", "x", "g")
      BM> Not tested!

      Thank you. This example does exactly what I wanted:

      strlen(substitute(getline("."), ".", "x", "g"))

      Here is a modified function, which counts selected characters in
      Visual mode:

      " If the argument is 0, newlines are not counted in blockwise visual mode
      fun! VisualCount(newlines)
      let mode = mode()
      let ret = ""
      if mode ==? 'v'
      let opt_report = &report
      let &report = 2147483647 " 2^31 - 1
      norm "-ygv
      let &report = opt_report
      let len = strlen(substitute(@-, ".", "x", "g"))
      if mode ==# 'V' && a:newlines == 0
      let len = len - (line("'>") - line("'<")) - 1
      elseif mode ==# 'v' && a:newlines == 0
      let len = len - (line("'>") - line("'<"))
      endif
      else
      let len = 0
      endif
      if len > 0
      let ret = '[' . len . ']'
      endif
      return ret
      endfun


      --
      Best regards,
      Valery Kondakoff
      http://www.nbk.orc.ru (Ne Bey Kopytom)
      http://www.nbk.orc.ru/mtb (MTB riding in Moscow)

      PGP key: mailto:pgp-public-keys@...?subject=GET%20strauss@...

      np: Anthony Rother - Red Light District (Unknown) [stopped]
    Your message has been successfully submitted and would be delivered to recipients shortly.