3

If i run C-x 3, when emacs starts up it will split window and creates two windows of equal size like this enter image description here

Now i run C-x 3 again it will split current window into two parts resulting in this

enter image description here

But whenver i create a vertical split, i want to auto adjust width of each window to equal size like this.

enter image description here How can i achieve this?

  • You can press "C-x +" after splitting to make all windows evenly spaced. Handy to have in your muscle memory. – InHarmsWay Sep 21 '15 at 12:59
  • @InHarmsWay is there a hook which will run after creating window? – ChillarAnand Sep 21 '15 at 13:02
  • That I'm not sure, but you could always define your own command that calls the two functions you need. Logically the same as a hook, and allows you to continue calling the original functions separately if desired. – InHarmsWay Sep 21 '15 at 13:05
  • @InHarmsWay thats fine, post it as answer? – ChillarAnand Sep 21 '15 at 13:08
  • 1
    Try the window-configuration-change-hook. However you may want to bind your own split commands for this instead as @InHarmsWay suggested. Using the hook would likely have side effects you don't want with commands that split windows for other purposes. – glucas Sep 21 '15 at 13:08
6

You can define your own command for this. This allows you to use it when desired, but not change the default behavior of the original commands, keeping them useful individually if desired:

  (defun my/split-window-evenly ()
    (interactive)
    (split-window-right)
    (balance-windows))

(global-set-key "\C-cb" 'my/split-window-evenly)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.