Search notes:

Vim functions: strchars vs strwidth vs strlen vs strdisplaywidth

A small script to demonstrate the difference between strchars, strwidth, strlen and strdisplaywidth.
" ../run_ _str_len_width_chars_etc

redir > _str_len_width_chars_etc.out

fu! ShowWidths(string) " {

    echo a:string
    echo '  strchars:        ' . strchars       (a:string)
    echo '  strwidth:        ' . strwidth       (a:string)
    echo '  strlen:          ' . strlen         (a:string)
    echo '  strdisplaywidth: ' . strdisplaywidth(a:string)

    echo ''

endfu " }


call ShowWidths('abc')
" strchars:        3
" strwidth:        3
" strlen:          3
" strdisplaywidth: 3

call ShowWidths('ä')
" strchars:        1
" strwidth:        1
" strlen:          2
" strdisplaywidth: 1

call ShowWidths('せ')
" strchars:        1
" strwidth:        2
" strlen:          3
" strdisplaywidth: 2

call ShowWidths("\t")
" strchars:        1
" strwidth:        1
" strlen:          1
" strdisplaywidth: 8

redir END
q
Github repository about-vim, path: /vimscript/functions/_str_len_width_chars_etc.vim

See also

Vim: built in functions
VIM script

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1743217842, '3.138.118.52', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/vim/script/vimscript/functions/_str_len_width_chars_etc(86): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78