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.
I don’t think anybody ever want to play tetris inside Emacs, but it’s there!
The dired-mode enable us to “edit directory” (DIRectory EDitor), delete, rename, print etc.
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
emacs | rest of the world |
---|---|
frame | program window |
window | pane |
buffer | file |
kill | cut |
yank | paste |
region | selection |
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.
Menu bar
Located at the top of each frame.
Keys
Keyboard shortcuts, for examples:
|
|
M
stands for Alt
, so press and hold Alt
, press x
, release and type tetris
and press Enter
.
|
|
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:
|
|
To get all the available keybindings in the current buffer/mode:
|
|
Tutorial
This will get you started with Emacs, open the tutorial buffer with:
|
|
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”).
|
|
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.
|
|
disable splash-screen
|
|
Disable use-file-dialog
|
|
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.
|
|
resize frame pixelwise
Neccessary if you’re using window-managers.
|
|
Ask for confirmatino when exiting Emacs
The default is don’t ask for confirmation (nil)
|
|
enable save-place-mode
Save the point to the last place when the buffer is previously visited.
|
|
enable savehist-mode
Save the minibuffer history.
|
|
separate Customization file elsewhere
By default this file is appended to the init file, which usually not desired.
|
|
this snippet will ensure the file is separated and loaded when starting Emacs.
Ignore case in completion
|
|
enable global auto-revert-mode
This mode enable auto-revert buffer when the file on the disk changes.
|
|
also enable it for non-file buffers
|
|
This way, both file buffers and buffers with a custom revert-buffer-function
will be auto-reverted.
Don’t generate message when auto-reverting
|
|
electric-pair-mode
This mode is useful when editing Emacs Lisp buffer, we’ll enable this on every programming mode (prog-mode) via hook:
|
|
Use clipboard for cutting and pasting
|
|
Delete to trash
Specifies whether to use the system’s trash can.
|
|
Automatic Compression
|
|
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.
|
|
recent file
|
|
prefer spaces than tabs
|
|
visualize empty lines
|
|
Ease CamelCase word navigation
|
|
This way editPost
is considered a two word.
disable electric-indent-mode
|
|
enable delete-selection-mode
|
|
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:
|
|