Emacs: An Editor That Lives in the Terminal
Lesson 5 of 11
5Emacs: An Editor That Lives in the Terminal
Emacs is an endlessly extensible text editor driven by key chords. You will understand its own vocabulary (buffer, point, mark, kill ring) and learn the core shortcuts by their logic rather than blind memorization.
What the picture shows: You set the mark, move point so the region forms, then C-w kills it into the kill ring and C-y yanks it back wherever you want.
Map of this part
The concepts in order, click any one to jump to it:
Two ways into the same idea
Emacs is like a woodworking shop you can add any tool to. Everything you do in it, even moving the cursor, is a named command with a shortcut. The shortcuts look like a lot at first, but they follow a logic: Ctrl for small units like characters and lines, Alt for bigger ones like words and sentences.
Emacs is an editor programmable in Emacs Lisp. Open text lives in a buffer, the cursor is the point, and the mark together with the point defines a region. Whatever you cut goes to the kill ring, recalled with C-y then M-y, and any command can be called by name with M-x.
Before You Start
🐚Shell navigation
You launch Emacs from the shell and need to know where your files are.
⌨️The Ctrl and Alt/Meta keys
Emacs chords are written C-x meaning Ctrl+x, and M-x meaning Meta (usually Alt or Esc) + x.
The Core Idea
1The buffer
What you see and edit in Emacs is not the file itself but an in-memory copy called a buffer. The file on disk changes only when you save. You can open many buffers and switch between them with C-x b.
2Point, mark and region
Point is the cursor position. The mark is a position you set with C-SPC. The text between mark and point is the region that cut and copy commands act on.
3The kill ring
In Emacs "kill" means cut and "yank" means paste. What you kill is not lost: it is stored in a ring holding several clips, so you can bring back text you cut a few steps ago.
4Everything is a command you can call
Every chord calls a named function. M-x lets you type the name of any command and run it even if you forgot its shortcut, the secret of extensibility: you can define your own commands.
Figure 1, The path of text in Emacs: select, then cut or copy into the kill ring, then yank.
C-g to cancel and return to normal.
How It Works: Shortcuts and the Editing Flow
| Task | Shortcut | How to remember |
|---|---|---|
| Open a file | C-x C-f | Find file |
| Save | C-x C-s | Save |
| Exit | C-x C-c | Close |
| Cancel anything pending | C-g | Get out |
| Search forward / backward | C-s / C-r | Search / Reverse |
| Kill rest of line | C-k | Kill |
| Kill / copy region | C-w / M-w | C-w cuts, M-w copies |
| Paste (yank) | C-y | Yank |
| Undo | C-/ or C-x u | Undo |
| Start / end of line | C-a / C-e | a is first, e is end |
| Switch buffer | C-x b | Buffer |
| Run command by name | M-x | eXecute |
emacs myfile.txt from the shell or C-x C-f inside Emacs.C-n next line, C-p previous, C-f forward a character, C-b back.C-k and pasting with C-y.C-x C-s.C-x C-c; if there are unsaved changes it will ask you.Worked Example: Everyday Editing Tasks
| Situation | What you do | Result |
|---|---|---|
| Move a line elsewhere | C-a, C-k, move, C-y | Line is now in the new spot |
| Copy a paragraph | C-SPC, move cursor, M-w, move, C-y | Paragraph appears twice |
| Cut something by mistake | C-/ | The cut is undone |
| Pressed something odd | C-g | Back to normal |
C-h t to open Emacs’s built-in interactive tutorial, the best way to learn hands-on within minutes.
Myth vs. Reality
| The myth | The reality |
|---|---|
| Emacs is hard because it needs hundreds of shortcuts memorized. | A dozen shortcuts suffice for daily work; for the rest there is M-x and the built-in help. |
| Emacs is just a text editor. | It is a programmable environment: it can read mail, manage files and run a shell because everything in it is a modifiable function. |
| If you close Emacs abruptly you lose your work. | It keeps temporary auto-save files, but do not rely on them; save yourself. |
Where Is This Idea Actually Used?
🖧Editing on servers
With no graphical interface, a terminal editor is your tool.
🧬Writing code
Per-language modes provide highlighting and automatic indentation.
🗂️Notes management
The popular org-mode organizes tasks and notes.
🏛️Free software history
Started by Richard Stallman within the GNU project, one of the oldest continuously maintained free programs.
Try it yourself
You typed in Emacs, then ran ls in the shell and the file is unchanged. Why?
A buffer is a copy in memory; the file on disk changes only when you save with C-x C-s.
Emacs looks “stuck” after an accidental keypress. What is your first move?
Emacs is usually waiting for the rest of a key sequence; C-g cancels the pending command and returns you to normal.
Which shortcut copies the selected region without cutting it?
C-w cuts (kills) and M-w copies; both put the text on the kill ring, and C-y yanks it back.
Quick Review Flashcards
C-x C-s do?C-gM-x for?Check Your Understanding
Why does the file not change while I type in Emacs?
Because you are editing an in-memory buffer; the file changes only on save.
How do you copy two lines elsewhere?
Set the mark with C-SPC at the start of line one, move to the end of line two, M-w, move, then C-y.
You forgot a command’s shortcut; what do you do?
Use M-x and type the command’s name, or open help with C-h.
Resources for this part
Sorted by kind: start with the official docs when you want the precise reference, or with an article or video when you want the explanation first.
Resources for this lesson
Grouped by type. Start with the official docs for precision, or an article or video for the explanation.
Official docs2
Done with this lesson?
Sign in to save your progress.