The simplest way to do this is probably with session files, which are vim scripts (that vim can automatically produce for you) that will restore a previous editing environment.
You can create a new session file using :mksession <filename>
. You can restore that session by executing the generated session script, :source <filename>
.
Thus, you could save the current session prior to maximizing a window and restore it when you want to "unmaximize" the window.
Using this, you could remap the appropriate windowing commands to save a session beforehand, and add a new mapping for one to "undo" the last windowing command by restoring the session. For example:
nnoremap <C-w>o :mksession! ~/session.vim<CR>:wincmd o<CR>
and so on for all the windowing commands you want to support (see :help CTRL-W
, there's a lot). The !
prevents errors relating to overwriting an existing session file.
nnoremap <C-w>u :source ~/session.vim<CR>
to "undo" the last windowing command.
If you wanted to be particularly robust, you could extend this via functions to save the session files in a stack and pop them off to get a full undo chain, although at that point it's probably more efficient to write a bunch of functions to track the window command history in memory... at which point you are likely duplicating the plugins that do this sort of thing already.