feat(:restart)!: ":restart" (no bang) saves/restores session #40321

Problem:
`:restart` does not preserve window layout, etc.

Solution:
- Change `:restart` to save/restore a session automatically.
- Introduce "bang" variant `:restart!` to restart *without* session
  save/restore.
- Introduce `v:startreason`.
- `ZR` maps to `:restart!`.
This commit is contained in:
Nathan Zeng
2026-06-29 07:55:23 -07:00
committed by GitHub
parent 39e9c1754a
commit 845b66dd4a
14 changed files with 231 additions and 63 deletions

View File

@@ -402,8 +402,8 @@ describe('startup --listen', function()
end)
end)
it(':restart works in headless server (no UI)', function()
t.skip(is_os('win'), 'FIXME: --listen not preserved by :restart on Windows')
it(':restart! works in headless server (no UI)', function()
t.skip(is_os('win'), 'FIXME: --listen not preserved by :restart! on Windows')
local nvim0 = clear()
local server_pipe = n.new_pipename()
@@ -428,14 +428,14 @@ it(':restart works in headless server (no UI)', function()
end)
n.set_session(n.connect(server_pipe))
n.expect_exit(n.command, 'restart')
n.expect_exit(n.command, 'restart!')
n.set_session(n.connect(server_pipe))
eq(1, api.nvim_get_vvar('vim_did_enter'))
eq('restart', api.nvim_get_vvar('startreason'))
eq('restart', n.eval('g:early_startreason'))
eq('restart!', api.nvim_get_vvar('startreason'))
eq('restart!', n.eval('g:early_startreason'))
-- TODO: [command] is currently not executed without UI
-- n.expect_exit(n.command, 'restart lua _G.new_server = 1')
-- n.expect_exit(n.command, 'restart! lua _G.new_server = 1')
-- n.set_session(n.connect(server_pipe))
-- eq(1, n.exec_lua('return _G.new_server'))
end)