commit d464dffd2fe5ceee77944fa9946547548b30d9e1
parent e4e6605943665c2f7b3bb9f7e2b065188935bd33
Author: alf171 <alfonso.laffont@gmail.com>
Date: Sun, 16 Nov 2025 14:08:38 -0500
fix: make :restart respect 'confirm' option #36531
When 'confirm' is set and there are unsaved buffers,
:restart now prompts before quitting, matching the behavior of :quit.
Diffstat:
2 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
@@ -4905,11 +4905,22 @@ static void ex_restart(exarg_T *eap)
});
set_vim_var_list(VV_ARGV, argv_cpy);
}
- char *quit_cmd = (eap->do_ecmd_cmd) ? eap->do_ecmd_cmd : "qall!";
- Error err = ERROR_INIT;
- if ((cmdmod.cmod_flags & CMOD_CONFIRM) && check_changed_any(false, false)) {
+
+ bool confirm = (p_confirm || (cmdmod.cmod_flags & CMOD_CONFIRM));
+ if (confirm && check_changed_any(false, false)) {
return;
}
+
+ char *quit_cmd;
+ if (eap->do_ecmd_cmd) {
+ quit_cmd = eap->do_ecmd_cmd;
+ } else if (confirm) {
+ quit_cmd = "qall";
+ } else {
+ quit_cmd = "qall!";
+ }
+
+ Error err = ERROR_INIT;
restarting = true;
nvim_command(cstr_as_string(quit_cmd), &err);
if (ERROR_SET(&err)) {
diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua
@@ -378,6 +378,14 @@ describe('TUI :restart', function()
tt.feed_data('C\013')
screen:expect({ any = vim.pesc('[No Name]') })
+ -- Check :restart respects 'confirm' option.
+ tt.feed_data(':set confirm\013')
+ tt.feed_data(':restart\013')
+ screen:expect({ any = vim.pesc('Save changes to "Untitled"?') })
+ tt.feed_data('C\013')
+ screen:expect({ any = vim.pesc('[No Name]') })
+ tt.feed_data(':set noconfirm\013')
+
-- Check ":confirm restart <cmd>" on a modified buffer.
tt.feed_data(':confirm restart echo "Hello"\013')
screen:expect({ any = vim.pesc('Save changes to "Untitled"?') })