On 2009-04-15, Yukihiro Nakadaira <[email protected]> wrote:
>
> /\%v pattern is useful for it.
>
> function! StrWidth(str, ...)
>    let vcol = get(a:000, 0, 0)
>    let w = 0
>    for c in split(a:str, '\zs')
>      let w += CharWidth(c, w + vcol)
>    endfor
>    return w
> endfunction
>
> function! CharWidth(c, ...)
>    let vcol = get(a:000, 0, 0)
>    if a:c == ""
>      return 0
>    elseif a:c == "\t"
>      return TabWidth(vcol)
>    elseif a:c =~ '^.\%2v'    " single char
>      return 1
>    elseif a:c =~ '^.\%3v'    " double char, ^X
>      return 2
>    elseif a:c =~ '^.\%5v'    " <XX>
>      return 4
>    else                      " other?
>    endif
>    return 0
> endfunction
>

Thanks!  I guess I was hoping for some builtin function like wcswidth in
C99.  But this will do.

-Yozo



--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to