Years ago I defined this function in my init.el
file:
;; Toggle between split windows and a single window
(defun toggle-windows-split()
"Switch back and forth between one window and whatever split of windows we might have in the frame. The idea is to maximize the current buffer, while being able to go back to the previous split of windows in the frame simply by calling this command again."
(interactive)
(if (not(window-minibuffer-p (selected-window)))
(progn
(if (< 1 (count-windows))
(progn
(window-configuration-to-register ?u)
(delete-other-windows))
(jump-to-register ?u))))
(my-iswitchb-close))
and then I add a keybinding for it:
(define-key global-map (kbd "C-|") 'toggle-windows-split)
I don't remember if I wrote this myself or got it from someone else. There are similar implementations defined here but I haven't tried them: https://www.emacswiki.org/emacs/ToggleWindowSplit