emacs: buffers and windows

Basic key bindings

Key Bindings Purpose
C-x C-f Find (open) a file
C-x C-s Save the buffer
C-x b Switch buffer
C-x k Kill (close) a buffer
C-x C-b Display all open buffers
C-x C-c Exits Emacs
ESC ESC ESC Exits out of prompts, regions, prefix arguments and returns to just one window
C-/ Undo changes
F10 Activates the menu bar

You have several options when Emacs asks you to save a file:

Key Binding Purpose
Y or yes Saves the file
N or DEL Skips current buffer
q or RET Aborts the save, continues with exit
C-g Aborts save and the exit
! Save all remaining buffers
d Diff the file on the file system with the one in the buffer

IDO mode

To enable it, type M-x ido-mode and then try C-x b or C-x C-f again.

You can enable it permanently by customizing the option ido-mode:

1
M-x customize-option RET ido-mode RET

You can also improve IDO's fuzzy matching by enabling flex matching:

1
M-x customize-option RET ido-enable-flex-matching RET

Windows Managment

Key Binding Purpose
C-x 0 Deletes the active window
C-x 1 Deletes other windows
C-x 2 Split window below
C-x 3 Split window right
C-x o Switch active window

move between windows with rebinding to M-o , add below to ~/.emacs.d/init.el

1
(global-set-key (kbd "M-o") 'other-window)

swich windows with shift key, S-<left>,S-<right>,S-<up>,S-<down>, add below to ~/.emacs.d/init.el

1
(windmove-default-keybindings)

Working with other windows

Key Binding Purpose
C-x 4 C-f Finds a file in the other window
C-x 4 d Opens M-x dired in the other window
C-x 4 C-o Displays a buffer in the other window
C-x 4 b Switches the buffer in the other window and makes it the active window
C-x 4 0 Kills the buffer and window

Frame Management

Frames are useful with multi-monitor setups.

1
2
emacs --daemon
emacsclient -nw
Key Binding Purpose
C-x 5 2 Create a new frame
C-x 5 b Switch buffer in other frame
C-x 5 0 Delete active frame
C-x 5 1 Delete other frames
C-x 5 C-f Finds a file in the other window
C-x 5 d Opens M-x dired in the other window
C-x 5 C-o Displays a buffer in the other window

Gracefully shutdown daemon

1
emacsclient -e '(save-buffers-kill-emacs)'