diff --git a/runtime/doc/editing.txt b/runtime/doc/editing.txt index b3a1e759ad..f6a3a1b240 100644 --- a/runtime/doc/editing.txt +++ b/runtime/doc/editing.txt @@ -1209,8 +1209,10 @@ ZZ Write current file, if modified, and close the current ZQ Quit without checking for changes (same as ":q!"). *ZR* -[count]ZR Performs |:restart!|. If a [count] is given, restarts - without checking for changes (":restart! +qall!"). +[count]ZR Performs |:restart|. If a [count] of [1-8] is given, + the session is not restored (":restart! +qall"). If a + [count] of 9 is given, restarts without restoring the + session or checking for changes (":restart! +qall!"). MULTIPLE WINDOWS AND BUFFERS *window-exit* diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt index 456b2798cc..82ef5dd0e7 100644 --- a/runtime/doc/news.txt +++ b/runtime/doc/news.txt @@ -192,7 +192,7 @@ EDITOR (Or use `:{range}lua` to skip the detection.) • |:wall| with |++p| auto-creates missing parent directories. • |:restart| now restores the current session while |:restart!| does not. -• |ZR| restarts Nvim (|:restart!|). +• |ZR| restarts Nvim (|:restart|). EVENTS diff --git a/src/nvim/normal.c b/src/nvim/normal.c index b2b64b1c5d..ed6ce1c1ca 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -3299,12 +3299,14 @@ static void nv_Zet(cmdarg_T *cap) do_cmdline_cmd("q!"); break; - // "ZR": restart. With count, restart without checking for changes. + // "ZR": restart. With count, does not restore session/check for changes. case 'R': - if (cap->count0 >= 1) { + if (cap->count0 >= 1 && cap->count0 <= 8) { + do_cmdline_cmd("restart!"); + } else if (cap->count0 == 9) { do_cmdline_cmd("restart! +qall!"); } else { - do_cmdline_cmd("restart!"); + do_cmdline_cmd("restart"); } break; diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 01e5a99b53..be7fb790df 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -340,7 +340,12 @@ describe('TUI :restart', function() end) it('ZR', function() - -- Just exercise ZR, don't need to test all :restart! functionality here. + -- Just exercise ZR, don't need to test all :restart functionality here. + local file = 'Xtest-restart-file' + write_file(file, 'foo') + finally(function() + os.remove(file) + end) local server_pipe = new_pipename() local server_session finally(function() @@ -363,18 +368,30 @@ describe('TUI :restart', function() finally(function() os.remove(testlog) end) - screen:expect({ any = '%[No Name%]' }) + feed_data(':edit ' .. file .. '\r') + screen:expect({ any = 'foo' }) server_session = n.connect(server_pipe) local _, starttime = server_session:request('nvim_eval', 'v:starttime') + -- ZR preserves screen state + tt.feed_data('ZR') + starttime, server_session = assert_restarted(starttime, server_session, server_pipe) + screen:expect({ any = 'foo' }) + + -- [1-8]ZR does not preserve screen state + tt.feed_data('1ZR') + screen:expect({ any = vim.pesc('[No Name]'), none = 'foo' }) + -- ZR on modified buffer fails with E37. tt.feed_data('ifoo\027') tt.feed_data('ZR') screen:expect({ any = 'E37:' }) - - -- [count]ZR discards unsaved changes. tt.feed_data('1ZR') + screen:expect({ any = 'E37:' }) + + -- [9]ZR discards unsaved changes. + tt.feed_data('9ZR') screen:expect({ any = vim.pesc('[No Name]') }) starttime, server_session = assert_restarted(starttime, server_session, server_pipe)