When opening 2 files in emacs, how can I have them appear side-by-side?
The following (to add to your .emacs) makes the window splitting default result in side-by-side buffers (rather than one above the other):
(setq split-height-threshold nil)
(setq split-width-threshold 0)
This default will also apply when you run a command such as find-file-other-window
(Ctrlx4f).
(On the other hand, to manually split your window to get two side-by-side buffers, consider this answer).
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)