GNU Emacs
Introduction
GNU Emacs is a free implementation of Emacs, a family of text editors. It is an extensible, customizable and self-documenting real-time display editor. It provides a wide range of functionalities. For example, it can open multiple files, indent text, edit remote file, but can also act as a news/email client, display pdf, images, spawn a shell or maintain a calendar.
One philosophy behind GNU Emacs is to use a single program to answer all needs, making all features communicating between them with ease, implying a lighter desktop environment, and a common set of bindings to navigate between and inside each feature.
Another philosophy is to open Emacs a single time when booting its system and keep it open until the shutdown, in order to avoid the initial startup time.
It is possible to open the text-editor within the terminal with the
command emacs -nw
, -nw
referring to \'no window\'.
Commands
Emacs commands are invoked with either the Control
key, symbolized as
a capital C
, or either the Meta
key (Default is Alt
), symbolized
as a capital M
.
All commands can be invoked using their name, by using M-x
followed by
the function name.
It is possible to display all commands using M-x describe-bindings
Navigation
Here are some the basic navigation commands, some resources in the next sections should help you learn more about them.
C-f
: Move right (forward)C-b
: Move left (backward)C-p
: Move up (previous)C-n
: Move down (next)C-x C-c
: Close EmacsC-x C-f
: Open a fileC-x C-s
: Save fileC-x 2
: Split window horizontallyC-x 3
: Split window verticallyC-x o
: Focus another windowsC-x 0
: Close focused window
Help
One of the greatest functionality of Emacs is the huge documentation that comes with it. It is possible to display help for each functions or keybinding using a simple command.
By using C-h C-h
it is possible to see all help commands available.
Using C-h
followed by the key associed with the category invoke its
help functionality.
The two major help commands are the following:
- A tutorial explaining keybindings can be invoked using
M-x help-with-tutorial
or shortlyC-h t
. The keybindings are the same as most terminals. - The Emacs Manual can be opened using
M-x info-emacs-manual
orC-h r
.
Other great help features exist, for example C-h f
offers the
possibility to enter the name of a command to read a short documentation
about it.
Default features
Emacs provides several useful features by default, we can mention some of them:
man
You can read man page within emacs using M-x man
, it will search by
default the word under the cursor.
dired
When opening a directory, a special mode called dired is used to perform actions on files. The most used bindings are the following:
- e : Open file in edit mode
- v : Open file in visual mode (read only)
- d : Mark a file for deletion
- u : Unmark a file
- x : Execute the deletion
- C : Copy file
- R : Rename the file
- M : Change permissions
- G : Change group
- S : Create a symlink
- q : Quit buffer
org
A whole framework aimed to improve organization in plaintext, named org, is integrated in GNU Emacs. It is a plain text markup language having as advantage to be rendered directly into Emacs, having special bindings to improve note taking and working in symbiosis with other org features.
For example, it is possible to annotate sections of text with specials tags (Timedate, TODO, AUTHORS, ...), to include link to local files, or even to indicate sections of code, evaluate them and add results into the file.
Basic configuration
Emacs Lisp
GNU Emacs is extremely powerful and easy regarding configurations. All
its configuration is possible using Emacs Lisp
, a flavor of Lisp
language. Configurations are located within the ~/.emacs
file.
To change bindings, use the function global-set-key
:
;; Set the binding "C-c h" for the function 'replace-string'
(global-set-key (kbd "C-c h") 'replace-string)
To change configuration value, use the function setq
:
;; Set offset to 4 in c file
(setq c-basic-offset 4)
It is also possible to apply a configuration only in certain circumstances, by calling a function only when a mode is activated.
;; Set the python indentation to 2, when opening a python file
(add-hook 'python-mode-hook (lambda () (setq python-indent-offset 2)))
Visual configuration
Emacs also provides a visual and easy mode to help customize the editor.
To use it, just invoke M-x customize
.
To customize the text, you can invoke M-x list-faces
. It will show a
list of all faces used by Emacs, referring to all displayed text under
all circumstances. You can find the name of the face used by a text by
invoking M-x describe-text-properties
having the cursor on the
targeted text.
External packages
It is possible to add custom packages by using Emacs packages manager,
for example MELPA
. Listing and installing packages are possible using
the command M-x list-packages
.
Some of them are well known and could be useful, here is a short list:
- Magit : Providing a git client inside Emacs
- evil : Layer to use vim bindings
- Treemacs : Adding a tree layout file explorer
Configuration framework
Configuration frameworks are set of configuration files added to Emacs to provides a choice of external packages already configured.
The most popular ones are the following:
- Doom emacs
- Spacemacs
Useful links
Here is some useful links to go further: