Emacs: split into multiple windows vertically
In standard Emacs, pressing C-x 3 will call function split-window-right to
split the current window into two identical windows.
Sometimes I want to get more than two windows, so I wrote this little function:
(defun wenshan-split-window-vertical (&optional wenshan-number) "Split the current window into `wenshan-number' windows and balance all windows" (interactive "P") (setq wenshan-number (if wenshan-number (prefix-numeric-value wenshan-number) 2)) (while (> wenshan-number 1) (split-window-right) (setq wenshan-number (- wenshan-number 1))) (balance-windows))
It calls split-window-right multiple times to get multiple new windows and
finally calls balance-window to adjust the sizes of all windows.
eval this function, then you could press M-x wenshan-split-window-vertical
(thanks to the auto-completion functionality, you won’t need to type all these
characters) to call it. By default, it creates two windows, if you need to get
more than two (as the original purpose of this function), you could type:
M-5 M-x wenshan-split-window-vertial