From 25000be8457f5c2eec12f9551d013ca70cd89e59 Mon Sep 17 00:00:00 2001 From: Shadman Date: Tue, 24 Jun 2025 19:52:24 +0600 Subject: [PATCH] fix(prompt): "%" prefix repeated on newlines with formatoptions+=r #34584 Problem: With `formatoptions+=r`, the prompt prefix "%" is treated as comment-start (because of global default 'comments' option contains "%"), so it gets added to the start of the line when a new line is input in a prompt. Solution: Unset the 'comments' option in prompt buffers by default. --- src/nvim/optionstr.c | 5 ++++- test/functional/legacy/prompt_buffer_spec.lua | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/nvim/optionstr.c b/src/nvim/optionstr.c index d25f60da0e..9d36418693 100644 --- a/src/nvim/optionstr.c +++ b/src/nvim/optionstr.c @@ -696,8 +696,11 @@ const char *did_set_buftype(optset_T *args) || opt_strings_flags(buf->b_p_bt, opt_bt_values, NULL, false) != OK) { return e_invarg; } - // buftype=prompt: set the prompt start position to lastline. + // buftype=prompt: if (buf->b_p_bt[0] == 'p') { + // Set default value for 'comments' + set_option_direct(kOptComments, STATIC_CSTR_AS_OPTVAL(""), OPT_LOCAL, SID_NONE); + // set the prompt start position to lastline. pos_T next_prompt = { .lnum = buf->b_ml.ml_line_count, .col = 1, .coladd = 0 }; RESET_FMARK(&buf->b_prompt_start, next_prompt, 0, ((fmarkv_T)INIT_FMARKV)); } diff --git a/test/functional/legacy/prompt_buffer_spec.lua b/test/functional/legacy/prompt_buffer_spec.lua index a24e1b0b9c..0f49b8833a 100644 --- a/test/functional/legacy/prompt_buffer_spec.lua +++ b/test/functional/legacy/prompt_buffer_spec.lua @@ -273,6 +273,22 @@ describe('prompt buffer', function() {1:~ }|*3 {5:-- INSERT --} | ]]) + + -- % prompt is not repeated with formatoptions+=r + source([[ + bwipeout! + set formatoptions+=r + set buftype=prompt + call prompt_setprompt(bufnr(), "% ") + ]]) + feed('iline1line2') + screen:expect([[ + other buffer | + % line1 | + line2^ | + {1:~ }|*6 + {5:-- INSERT --} | + ]]) end) it('can put (p) multiline text', function()