From: Hirohito Higashi Date: Thu, 18 Jun 2026 19:31:18 +0000 (+0000) Subject: patch 9.2.0676: MS-Windows: cannot switch to a buffer with '%' in its name X-Git-Tag: v9.2.0676^0 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1a96e07bf6ba46f4b6f50a861d755d0fbc89dabb;p=thirdparty%2Fvim.git patch 9.2.0676: MS-Windows: cannot switch to a buffer with '%' in its name Problem: On MS-Windows it is not possible to switch to a buffer by name with ":b" (including via command-line completion) when the buffer name contains '%'. Solution: Do not escape '%' and '#' for the ":buffer" command on MS-Windows. Since ":buffer" has no EX_XFILE these are not expanded, and escaping them as "\%"/"\#" makes buffer name matching fail when '%'/'#' is in 'isfname' (the backslash is treated as a path separator). fixes: #20529 closes: #20548 Co-Authored-By: Claude Opus 4.8 (1M context) Signed-off-by: Hirohito Higashi Signed-off-by: Christian Brabandt --- diff --git a/src/testdir/test_buffer.vim b/src/testdir/test_buffer.vim index 4f0f1acb24..733ef65434 100644 --- a/src/testdir/test_buffer.vim +++ b/src/testdir/test_buffer.vim @@ -935,4 +935,19 @@ func Test_split_window_in_BufLeave_from_switching_buffer() bwipe! Xb endfunc +" Switch to a buffer whose name contains '%' via completion (#20529). +func Test_buffer_switch_to_name_with_percent() + CheckMSWindows + + let bufnr = bufadd('Xpercent%name') + call setbufvar(bufnr, '&buflisted', 1) + call bufload(bufnr) + enew + + call feedkeys(":b Xpercent\\", 'xt') + call assert_equal(bufnr, bufnr('%')) + + exe 'bwipe! ' .. bufnr +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/version.c b/src/version.c index 14ebcf3433..5aa9fde1c1 100644 --- a/src/version.c +++ b/src/version.c @@ -759,6 +759,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 676, /**/ 675, /**/ diff --git a/src/vim.h b/src/vim.h index 640afc62ed..0e1cc1d27a 100644 --- a/src/vim.h +++ b/src/vim.h @@ -343,7 +343,10 @@ #endif #ifdef BACKSLASH_IN_FILENAME # define PATH_ESC_CHARS ((char_u *)" \t\n*?[{`%#'\"|!<") -# define BUFFER_ESC_CHARS ((char_u *)" \t\n*?[`%#'\"|!<") +// '%' and '#' are not escaped for ":buffer": it has no EX_XFILE, so they are +// not expanded, and escaping them as "\%"/"\#" breaks buffer name matching +// when '%'/'#' is in 'isfname' (backslash treated as a path separator). +# define BUFFER_ESC_CHARS ((char_u *)" \t\n*?[`'\"|!<") #else # ifdef VMS // VMS allows a lot of characters in the file name