Skip to content

Linux Foundations / Find your way around Linux ยท Step 55 of 63

Lesson: EmacsSwitch
โ† Linux Foundations

Shell and files

Emacs

Start Emacs in a terminal and learn how to read and type its key notation.

Emacs is a long-lived, highly extensible text editor from the GNU project. Unlike Vim, it has no separate insert mode to enter: you open a file and type. Commands are given with modifier keys.

Installing and starting

Your system may not have Emacs yet. To install it:

bash
sudo apt install emacs-nox    # Debian, Ubuntu
sudo dnf install emacs-nox    # Fedora and relatives

Start it inside the terminal with:

bash
emacs -nw notes.txt

-nw means "no window system". It matters when a graphical build is installed and you want to stay in the terminal. With emacs-nox it runs there anyway.

Key notation

The documentation writes keys in a compact form:

  • C-x means hold Ctrl and press x.
  • M-x means hold Meta and press x. Meta is usually the Alt key. You can also press Esc, release it, then press x.
  • C-x C-s means Ctrl-x followed by Ctrl-s.
  • C-x b means Ctrl-x, then a plain b.

Watch the difference between the last two. Keeping Ctrl held can run another command.

The screen

From top to bottom you will see:

  • The text area, showing a buffer (the text held in memory).
  • The mode line, with the buffer name, position and current mode.
  • The echo area, where messages appear. When Emacs asks you something, this line is called the minibuffer.

In the mode line, ** near the left means the buffer has unsaved changes.

Commands by name

Every action in Emacs is a named command. Keys are shortcuts to them. Press M-x, type the name and press Enter:

text
M-x display-line-numbers-mode

This one shows line numbers (Emacs 26 and later). Tab completes partial names.

The escape hatch

If you pressed something by mistake, or a prompt is waiting at the bottom, press C-g. It cancels the current command. Learn this one first.

To leave Emacs, press C-x C-c. It asks about unsaved files before closing.

A built-in tutorial

Press C-h t to open the Emacs tutorial, a practice text you work through inside the editor. The full GNU Emacs manual is available online.

Some terminals or desktop environments grab certain key combinations for themselves. If a shortcut does nothing, check your terminal settings or use the Esc form of Meta.

Try it

  1. Start emacs -nw hello.txt.
  2. Type a sentence and watch the mode line change.
  3. Press C-x, then C-g to cancel.
  4. Save with C-x C-s.
  5. Exit with C-x C-c, then check with cat hello.txt.

Check your understanding

Emacs

All 5 sections ยท no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.