Re: Wrong characters count when using utf-8
- Valery Kondakoff wrote:
> Tuesday, May 27, 2003, you wrote to me:Hmm, there are several methods, but I suppose the good old ":s" method
> >> > As far as I understand the character count is _not_ changed when
> >> > converting, but wrong character count is displayed.
> BM> The byte count changes. Using "chars" in the file message is an old Vi
> BM> habit. Look at this as the C language "char", which is actually a byte.
> Aha. Now I understand this. Thank you for explanation. But I still
> don't understand how can I count _characters_, not bytes when using
This ignores composing characters.
You can also use virtcol(), although it gets confused by Tabs and wide
If you want a function you could use something like:
strlen(substitute(getline(".")), ".", "x", "g")
Often you're less important than your furniture. If you think about it, you
can get fired but your furniture stays behind, gainfully employed at the
company that didn't need _you_ anymore.
(Scott Adams - The Dilbert principle)
/// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
/// Creator of Vim - Vi IMproved -- http://www.Vim.org \\\
\\\ Project leader for A-A-P -- http://www.A-A-P.org ///
\\\ Help AIDS victims, buy at Amazon -- http://ICCF.nl/click1.html ///
- 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
" If the argument is 0, newlines are not counted in blockwise visual mode
let mode = mode()
let ret = ""
if mode ==? 'v'
let opt_report = &report
let &report = 2147483647 " 2^31 - 1
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("'<"))
let len = 0
if len > 0
let ret = '[' . len . ']'
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]