Make :only ex command reversible

Sep. 22, 2017

The :only ex command is one of my most used ones. Here’s how it can be tweaked so that it doesn’t only (pun intended) hide all the other windows, but it restores them when re-executed. it You can think of it as a zoom/un-zoom command.

(use-package zygospore
  :ensure t
  :commands zygospore-toggle-delete-other-windows
  :init
  (evil-ex-define-cmd "only" 'zygospore-toggle-delete-other-windows))

The above snippet uses the zygospore package, which is but a thin wrapper around emacs core functionality. Go ahead and check out its code.

I often enter :On instead of :on which results in a disruption of my flow with an unpleasant “Unknown command” message. Why not create an alias then?

(evil-ex-define-cmd "Only" "only")