Skip to content

Commit f3044c7

Browse files
committed
Fortune: handle multibyte characters
1 parent 89bf0a5 commit f3044c7

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

autoload/startify/fortune.vim

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ endfunction
126126

127127
" Function: s:draw_box {{{1
128128
function! s:draw_box(lines) abort
129-
let longest_line = max(map(copy(a:lines), 'len(v:val)'))
129+
let longest_line = max(map(copy(a:lines), 'strwidth(v:val)'))
130130
if &encoding == 'utf-8' && get(g:, 'startify_fortune_use_unicode')
131131
let top_left_corner = ''
132132
let top_right_corner = ''
@@ -146,7 +146,7 @@ function! s:draw_box(lines) abort
146146
let bottom = bottom_left_corner . repeat(top_bottom_side, longest_line + 2) . bottom_right_corner
147147
let lines = [top]
148148
for l in a:lines
149-
let offset = longest_line - len(l)
149+
let offset = longest_line - strwidth(l)
150150
let lines += [side . ' '. l . repeat(' ', offset) .' ' . side]
151151
endfor
152152
let lines += [bottom]

doc/startify.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ How do I center my header/footer?~
838838
Try something along these lines:
839839
>
840840
function! s:filter_header(lines) abort
841-
let longest_line = max(map(copy(a:lines), 'len(v:val)'))
841+
let longest_line = max(map(copy(a:lines), 'strwidth(v:val)'))
842842
let centered_lines = map(copy(a:lines),
843843
\ 'repeat(" ", (&columns / 2) - (longest_line / 2)) . v:val')
844844
return centered_lines

0 commit comments

Comments
 (0)