Figure 1: Default Emacs

Figure 1: Default Emacs

The default Emacs is kinda boring and unintuitive, if you’re looking for a simple text editor, I really suggest other editors like nano, vim, or other graphical editors like gedit. The main advantage of using Emacs is that in can be more than just a text editor.

Figure 2: Tetris inside Emacs

Figure 2: Tetris inside Emacs

I don’t think anybody ever want to play tetris inside Emacs, but it’s there!

Figure 3: Emacs as a file manager

Figure 3: Emacs as a file manager

The dired-mode enable us to “edit directory” (DIRectory EDitor), delete, rename, print etc.

Figure 4: terminal in Emacs

Figure 4: terminal in Emacs

Eshell is a shell-like interpreter implemented in Emacs Lisp.

So, without any configuration, Emacs is very usable. But first we need to know the basic.

The Basic

terminology

emacsrest of the world
frameprogram window
windowpane
bufferfile
killcut
yankpaste
regionselection

Screen organization

Point

Basically, the cursor. By default, it is a solid block, the point appear on a character, but actually situated before the character under the cursor.

The echo area

The line at the very bottom of the frame, useful for displaying error messages or other informative messages.

The modeline

Located at the bottom of each window describing what’s going on in the current buffer. If there’s only one window, the mode line appears above the echo area; it is next-to-last in the frame.

Located at the top of each frame.

Keys

Keyboard shortcuts, for examples:

1
M-x tetris

M stands for Alt, so press and hold Alt, press x, release and type tetris and press Enter.

1
C-x C-f /path/to/some/file

C stands for Control, so press and hold CTRL, release, and press and hold CTRL, press f, release, and type some path to a file.

Modes

Each buffer is associated with something called major mode, and may have one or more active minor modes. Modes are sets of specific rules and/or keybindings for some buffers. There are read-only mode that forbid you from editing a buffer, there’s also language-specific modes for programming languages. To get a detailed description for the current buffer:

1
C-h m

To get all the available keybindings in the current buffer/mode:

1
C-h b

Tutorial

This will get you started with Emacs, open the tutorial buffer with:

1
C-h t

Configuration file

The configuration file itself is written in Emacs Lisp. The default location is traditionally in ~/.emacs, although Emacs will also look at ~/.emacs.el, /.emacs.d/init.el, and ~/.config/emacs/init.el. Though if you put your configuration files in ~/.config/emacs directory, be aware that it will not used if ~/.emacs file or ~/.emacs.d/ directory already exists,

Some useful sane defaults

use-short-answer

Use short answer for each confirmation (“y” or “n”, instead of “yes” or “no”).

1
(setq-default use-short-answers t)

disable menu / tool / scroll bar

Useful if you’re already comfortable with the keyboard-centric workflow, and you want to expand the buffer as much as possible.

1
2
3
(menu-bar-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)

disable splash-screen

1
(setq inhibit-startup-screen t)

Disable use-file-dialog

1
(setq use-file-dialog nil)

Since we don’t use the GUI (menu and toolbar).

resize windows pixelwise

This affect split-window, maximize-window, minimize-window, fit-window-to-buffer, and fit-frame-to-buffer.

1
(setq window-resize-pixelwise t)

resize frame pixelwise

Neccessary if you’re using window-managers.

1
(setq frame-resize-pixelwise t)

Ask for confirmatino when exiting Emacs

The default is don’t ask for confirmation (nil)

1
(setq confirm-kill-emacs #'yes-or-no-p)

enable save-place-mode

Save the point to the last place when the buffer is previously visited.

1
(setq save-place-mode t)

enable savehist-mode

Save the minibuffer history.

1
(savehist-mode t)

separate Customization file elsewhere

By default this file is appended to the init file, which usually not desired.

1
2
3
(setq custom-file (locate-user-emacs-file "custom.el"))
(when (file-exists-p custom-file)
  (load custom-file))

this snippet will ensure the file is separated and loaded when starting Emacs.

Ignore case in completion

1
2
3
(setq read-buffer-completion-ignore-case t
      read-file-name-completion-ignore-case t
      completion-ignore-case t)

enable global auto-revert-mode

This mode enable auto-revert buffer when the file on the disk changes.

1
(global-auto-revert-mode 1)

also enable it for non-file buffers

1
(setq global-auto-revert-non-file-buffers t)

This way, both file buffers and buffers with a custom revert-buffer-function will be auto-reverted.

Don’t generate message when auto-reverting

1
(setq auto-revert-verbose nil)

electric-pair-mode

This mode is useful when editing Emacs Lisp buffer, we’ll enable this on every programming mode (prog-mode) via hook:

1
(add-hook 'prog-mode-hook (lambda () (electric-pair-mode 1)))

Use clipboard for cutting and pasting

1
(setq select-enable-clipboard t)

Delete to trash

Specifies whether to use the system’s trash can.

1
(setq delete-by-moving-to-trash t)

Automatic Compression

1
(setq auto-compression-mode t)

Opening compressed file (zipped etc), will automatically uncompressed for reading, and compressed when writing.

enable font-lock-mode

This will enable syntax-highlighting and coloring.

1
(global-font-lock-mode t)

recent file

1
(recentf-mode 1)

prefer spaces than tabs

1
(set-default 'indent-tabs-mode nil)

visualize empty lines

1
(set-default 'indicate-empty-lines t)

Ease CamelCase word navigation

1
(global-subword-mode 1)

This way editPost is considered a two word.

disable electric-indent-mode

1
(setq electric-indent-mode nil)

enable delete-selection-mode

1
(delete-selection-mode 1)

When enabled, typed text will replace the selection if the selection is active, which is what I prefer. If disabled (nil), typed text is just inserted at point regardless of any selection.

Early init

This file is processed before init.el, must be named early-init.el and located in the same directory as the init.el. Example customization that should be placed here are:

  • Custom package management (this is loaded before the default package).

I use this for early UI setup:

1
2
3
(push '(menu-bar-lines . 0) default-frame-alist)
(push '(tool-bar-lines . 0) default-frame-alist)
(push '(vertical-scroll-bars) default-frame-alist)

After Configuration

Figure 5: After configuring

Figure 5: After configuring

Configuration generator

for those tldr users.

Emacs wiki

https://www.emacswiki.org/

Gnu Emacs Homepage

GNU Emacs tour

Emacs news