commit 25000be8457f5c2eec12f9551d013ca70cd89e59
parent 5871d267790987548d06e02afdd166e9e9c459e3
Author: Shadman <shadmansaleh3@gmail.com>
Date: Tue, 24 Jun 2025 19:52:24 +0600
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.
Diffstat:
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git 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
@@ -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('iline1<s-cr>line2')
+ screen:expect([[
+ other buffer |
+ % line1 |
+ line2^ |
+ {1:~ }|*6
+ {5:-- INSERT --} |
+ ]])
end)
it('can put (p) multiline text', function()