From d4106bade78b579406f41e16d6578a0c5dd11ebf Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 31 Oct 2025 17:16:09 +0800 Subject: [PATCH] vim-patch:9.1.1890: %P in 'statusline' doesn't behave as documented Problem: %P in 'statusline' doesn't behave as documented (after 9.1.1479). Solution: Make the percentage 3-chars wide when not translated. (zeertzjq) fixes: vim/vim#18669 closes: vim/vim#18671 https://github.com/vim/vim/commit/73a0de4a04b48ccaa0291f91fb69606c66d7cf8c Co-authored-by: Christ van Willegen --- src/nvim/buffer.c | 2 +- test/old/testdir/test_statusline.vim | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 07f6ccc81b..50d9277c11 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -3482,7 +3482,7 @@ int get_rel_pos(win_T *wp, char *buf, int buflen) char tmp[8]; // localized percentage value vim_snprintf(tmp, sizeof(tmp), _("%d%%"), perc); - return (int)vim_snprintf_safelen(buf, (size_t)buflen, _("%2s"), tmp); + return (int)vim_snprintf_safelen(buf, (size_t)buflen, _("%3s"), tmp); } /// Append (2 of 8) to "buf[]", if editing more than one file. diff --git a/test/old/testdir/test_statusline.vim b/test/old/testdir/test_statusline.vim index 6886700e83..a24c1f9964 100644 --- a/test/old/testdir/test_statusline.vim +++ b/test/old/testdir/test_statusline.vim @@ -166,9 +166,16 @@ func Test_statusline() call assert_match('^0,Top\s*$', s:get_statusline()) norm G call assert_match('^100,Bot\s*$', s:get_statusline()) - 9000 - " Don't check the exact percentage as it depends on the window size - call assert_match('^90,\(Top\|Bot\|\d\+%\)\s*$', s:get_statusline()) + " The exact percentage depends on the window height, so create a window with + " known height. + 9000 | botright 10split | setlocal scrolloff=0 | normal! zb + call assert_match('^90,89%\s*$', s:get_statusline()) + normal! zt + call assert_match('^90,90%\s*$', s:get_statusline()) + " %P should result in a string with 3 in length when not translated. + normal! 500zb + call assert_match('^5, 4%\s*$', s:get_statusline()) + close " %q: "[Quickfix List]", "[Location List]" or empty. set statusline=%q