|
1 | | -" Function to left and rigt align text. |
| 1 | +" Function to left and right align text. |
2 | 2 | " |
3 | 3 | " Written by: Preben "Peppe" Guldberg <[email protected]> |
4 | 4 | " Created: 980806 14:13 (or around that time anyway) |
@@ -256,18 +256,17 @@ function! Justify(...) range |
256 | 256 | let str = substitute(str, '\s\+$', '', '') |
257 | 257 | let str = substitute(str, '^\s\+', '', '') |
258 | 258 | let str = substitute(str, '\s\+', ' ', 'g') |
259 | | - " Use substitute() hack to get strlen in characters instead of bytes |
260 | | - let str_n = strlen(substitute(str, '.', 'x', 'g')) |
| 259 | + let str_n = strdisplaywidth(str) |
261 | 260 |
|
262 | 261 | " Possible addition of space after punctuation |
263 | 262 | if exists("join_str") |
264 | 263 | let str = substitute(str, join_str, '\1 ', 'g') |
265 | 264 | endif |
266 | | - let join_n = strlen(substitute(str, '.', 'x', 'g')) - str_n |
| 265 | + let join_n = strdisplaywidth(str) - str_n |
267 | 266 |
|
268 | 267 | " Can extraspaces be added? |
269 | 268 | " Note that str_n may be less than strlen(str) [joinspaces above] |
270 | | - if strlen(substitute(str, '.', 'x', 'g')) < tw - indent_n && str_n > 0 |
| 269 | + if strdisplaywidth(str) <= tw - indent_n && str_n > 0 |
271 | 270 | " How many spaces should be added |
272 | 271 | let s_add = tw - str_n - indent_n - join_n |
273 | 272 | let s_nr = strlen(substitute(str, '\S', '', 'g') ) - join_n |
|
0 commit comments