Y. Hida wrote:
>   Is there a way figure out how wide a string containing double-width
> characters are when displayed?  I'm trying to right-justify some strings
> in foldtext.

/\%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

function! TabWidth(vcol)
   return &tabstop - (a:vcol % &tabstop)
endfunction

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

Reply via email to