vim icon indicating copy to clipboard operation
vim copied to clipboard

`:restart` command

Open echasnovski opened this issue 1 year ago • 8 comments

Is your feature request about something that is currently impossible or hard to do? Please describe the problem. It is difficult to restart Vim while preserving current state, like buffer list, window/tabpage arrangement, ~~global/buffer variables/options~~, etc.

Describe the solution you'd like A new :restart command which restarts Vim while preserving as much current context as reasonably possible. Preferably only with wanted visual feedback that this has happened (a message, for example) and without flicker.

The expected effect is at least like executing the following steps:

  • :mksession! VIM_RESTART_SESSION.
  • :quitall
  • vim --cmd 'silent source VIM_RESTART_SESSION' --cmd 'call delete("VIM_RESTART_SESSION")'.

Describe alternatives you've considered Writing custom script which executes those three steps. It is not really clean and I would like to know if it is reasonably possible to restore more than built-in session can offer.

Additional context This function will be useful for clean reloading user config after there were some changes made. Plain resourcing might not deal well with cleaning up autocommands and mappings (especially ones coming from plugins).

echasnovski avatar Jan 23 '24 10:01 echasnovski

clean reloading user config after there were some changes made

this conflicts with:

preserving current state, like buffer list, window arrangement, global/buffer variables/options

noscript avatar Jan 24 '24 16:01 noscript

clean reloading user config after there were some changes made

this conflicts with:

preserving current state, like buffer list, window arrangement, global/buffer variables/options

Ah, yes, but only partially. Probably, I was thinking more about buffer list, windows and tabpages.

The general idea is to allow a quicker feedback for users working on their config. Like remove plugin from the config: this needs a proper close/open loop for clean effect. The closest example that I know of is i3 restart inplace: it makes changes in config current while preserving all windows and programs inside of them.

echasnovski avatar Jan 24 '24 16:01 echasnovski

I was thinking more about buffer list, windows and tabpages.

mksession can do it.

noscript avatar Jan 24 '24 16:01 noscript

I was thinking more about buffer list, windows and tabpages.

mksession can do it.

This is mentioned in the issue description, yes. Same as the motivation why actually using it is inconvenient for particular use case I am referring to..

echasnovski avatar Jan 24 '24 16:01 echasnovski

i3 restart inplace

In X11 you can un-parent and re-parent windows without killing their processes.

In Vim, some plugins may rely on external processes, which you won't be able to preserve. Other plugins create their variables just everywhere (buffer/window/tab/script/global), you cannot expect the plugins to work properly after restart unless you restore just everything (including the broken/buggy state), which defeats the purpose of restarting. So your only option is to let the plugins initialize themselves.

restarts Vim while preserving as much current context as reasonably possible

Cache invalidation is one of the hardest problems in computer science. Only you and plugin authors can decide how much preserving is reasonable. Vim cannot do it for you.

noscript avatar Jan 24 '24 17:01 noscript

@noscript I do not think your username is appropriate to even request to make a change of such sort.

without scripts how do you expect to interact closely with a kernel?

please consider your request, because your username frightens me.

MorganBergen avatar Jan 24 '24 17:01 MorganBergen

Only you and plugin authors can decide how much preserving is reasonable. Vim cannot do it for you.

Note that we're not talking about reloading a single plugin -- that is indeed impossible in general. This is a much weaker ask: restarting Vim without going back to the shell and possibly with a bit of :mksession tomfoolery. It does sound like it could be a reasonable compromise between the impossible and the (slightly) cumbersome (:q, vim).

The question is whether Vim's architecture allows this (dumping all state and then re-initializing from near-scratch) without a massive rewrite. (Neovim is in a much better position for this due to the decoupling of the TUI and the editor into separate processes.)

clason avatar Jan 24 '24 18:01 clason

The question is whether Vim's architecture allows this (dumping all state and then re-initializing from near-scratch) without a massive rewrite.

AFAIK you can dump everything (echo g:, echo b:, etc) except script variables.

noscript avatar Jan 24 '24 18:01 noscript