When opening 2 files in emacs, how can I have them appear side-by-side?

Here’s a function that will change a pair of vertical windows to a pair of horizontal windows:

(defun 2-windows-vertical-to-horizontal ()
  (let ((buffers (mapcar 'window-buffer (window-list))))
    (when (= 2 (length buffers))
      (delete-other-windows)
      (set-window-buffer (split-window-horizontally) (cadr buffers)))))

To do this automatically on startup, add this function to emacs-startup-hook:

(add-hook 'emacs-startup-hook '2-windows-vertical-to-horizontal)

Leave a Comment