Commit: patch 9.1.1890: %P in 'statusline' doesn't behave as documented

4 views
Skip to first unread message

Christian Brabandt

unread,
Oct 31, 2025, 5:15:22 AMOct 31
to vim...@googlegroups.com
patch 9.1.1890: %P in 'statusline' doesn't behave as documented

Commit: https://github.com/vim/vim/commit/73a0de4a04b48ccaa0291f91fb69606c66d7cf8c
Author: zeertzjq <zeer...@outlook.com>
Date: Fri Oct 31 09:10:05 2025 +0000

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: #18669
closes: #18671

Co-authored-by: Christ van Willegen <cvwil...@gmail.com>
Signed-off-by: zeertzjq <zeer...@outlook.com>
Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/buffer.c b/src/buffer.c
index 548df8051..6e4990abd 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -5430,7 +5430,7 @@ get_rel_pos(
char tmp[8];
// localized percentage value
vim_snprintf(tmp, sizeof(tmp), _("%d%%"), perc);
- return (int)vim_snprintf_safelen((char *)buf, buflen, _("%2s"), tmp);
+ return (int)vim_snprintf_safelen((char *)buf, buflen, _("%3s"), tmp);
}

/*
diff --git a/src/testdir/test_statusline.vim b/src/testdir/test_statusline.vim
index 9aa6aef66..4899bd0a0 100644
--- a/src/testdir/test_statusline.vim
+++ b/src/testdir/test_statusline.vim
@@ -168,9 +168,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
diff --git a/src/version.c b/src/version.c
index 4e0477dd9..5af88e611 100644
--- a/src/version.c
+++ b/src/version.c
@@ -729,6 +729,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1890,
/**/
1889,
/**/
Reply all
Reply to author
Forward
0 new messages