Lesson 6 — Terminals and CLI Coding Agents
An agent finishes a turn and prints an error with a path buried in it. You want that path back in the prompt, four lines down. With a mouse that is a drag, a copy, a click and a paste; with a thumb it is close to impossible. This lesson is the half of Vim that lives in terminals: reading and copying anything on screen, editing the line you're typing, and getting a real Esc to the program.
Everything you learned in Lessons 1–5 still applies. What changes is the job. A terminal running a coding agent is two things at once: a long prompt you are writing, and a screenful of output you are reading. A code editor has proper tools for the first and a terminal never has — so this lesson is about bringing them to it, and about getting things back out of the second.
Two halves, one grammar
Nothing you learned gets taken away here. The reading half — every motion, every text object, search, yank, registers, marks — is identical on both sides. What narrows is the writing half, and it narrows in exactly one direction: towards the line you are typing.
| Code editors | Terminals & CLI agents | |
|---|---|---|
| Motions, counts, text objects | ✅ | ✅ |
| Search, yank, registers, marks | ✅ | ✅ |
d c x r s D C | anywhere in the file | only on the line you are typing |
Undo (u, CtrlR) | ✅ | ❌ |
Command line (:%s, :42) | ✅ | ❌ |
| Visual block (CtrlV) | ✅ | ❌ |
| Macros | ✅ | ❌ |
The one rule
Read anywhere. Change only the line you're typing.
Moving, searching, selecting and copying work across the whole screen, and none of it reaches the program — you can browse an agent's output while it is still working and it will not notice. Editing works only on your current input line, and only when nothing is running. Everything further up has already happened; there is nothing there to change.
That is what makes this safe to switch on in the middle of a session: while you are reading, nothing you press can reach what is running.
Turning Vim keys on in a terminal
- The terminal's own menu — right-click, or long-press with a finger or Apple Pencil. Vim keys is the last item, and it affects that terminal only.
- Settings → Terminal → Vim keys — the default for every new terminal.
It is off by default, because it changes what Esc does.
With it on, nothing about typing changes. You start in insert mode, which is the ordinary terminal — every key reaches the program exactly as before, and you can use the terminal all day without pressing Esc once. Normal mode is somewhere you go when you want it, not a gate you pass through. Press Esc and a NORMAL badge appears in the corner; tap that badge at any time and you are back to typing.
Where this works: standalone terminals, Terminal nodes inside a workflow, and the panes running CLI coding agents such as Claude Code or Codex. Same keys in all three.
Who wrapped the line matters
A prompt too long for one row is drawn across several, and which of those rows you can edit depends on who did the wrapping.
- A shell lets the terminal wrap it. The rows are one logical line, so they behave as one:
ddclears the whole command, and a selection may cross them. - A CLI coding agent draws its own input box and breaks the lines itself. Each row is its own line as far as the terminal is concerned, so
ddclears the row you are on and an edit stays on that row.
Nothing is lost either way — reading, searching and copying never cared about rows. It is only worth knowing so that dd twice on a two-row agent prompt reads as correct rather than broken.
When editing works
Two things have to be true, and knowing them explains every time an editing key appears to do nothing:
- the cursor is on the line you are typing, and
- nothing is running — no command, no agent mid-turn.
Both true, and ciw diW dd x r all work. Otherwise the editing keys do nothing. Navigation, selection, search and yank never pause — reading back what an agent just said while it is still thinking is exactly what you want to be doing.
Two things you'll notice while editing
- It works the same everywhere — every shell, every full-screen program, every CLI agent. You don't have to remember which one you're in.
- Big edits are as fast as small ones.
d$costs no more thanx.
One more thing: i starts you typing where the cursor is. Move to a typo four words back, press i, and you are typing at that spot rather than at the end of the line. a puts you one character further on, and c does the same implicitly — ciw leaves you typing exactly where the old word was.
Esc Esc — interrupting an agent
You met this in Lesson 1. It matters most here. Because Esc is now a mode key, sending a real Esc takes a second press:
Escfrom insert mode → normal mode. Nothing is sent.Escagain from normal mode → a realEscgoes to the program. You stay in normal mode.
That second press is how you interrupt a turn or back out of a menu.
Copying what it just told you
Nothing in this section is new — it is Lesson 4 and Lesson 5 pointed at the one errand you will do most. An agent's reply is a block of non-blank rows, which is exactly what p means as a text object. So:
yip— copy the block you are in. The one key for "copy what it just told me" — but move up into the reply first.yiptakes the block your cursor is standing in, and when you pressEscthe cursor is still down at the prompt, so it would take your own input box instead.Esc, thenka few times or{to step up into the reply, thenyip.yi"— lift the path out ofcannot open "src/lib/parse.ts".yiW— copy a URL. RememberWoverw: a URL is oneWbut sevenws.gxorEnter— open the link on this line.
A yank crossing rows is allowed and comes out linewise, whole lines at a time. Every yank also lands on your system clipboard, so it can be pasted anywhere on the device, not just back into this terminal.
What isn't here, and what to use instead
| Not available | What to do instead |
|---|---|
u — no undo | Get back to typing and use your shell's own undo, Ctrl_ in bash and zsh |
| Editing above your input line | Copy it instead — yy, yiw, yip all work up there |
| Editing while something is running | Wait for it to finish. Reading and copying carry on working |
d or c across output rows | Only the line you are typing can change — across as many rows as the terminal wrapped it onto |
dip | yip — copying a block is almost always what you meant |
| Visual block, CtrlV | V for whole lines |
: commands | Nothing to substitute in — this is a prompt, not a file |
. after a change that ended in typing | Retype it. . repeats deletions, and 3. repeats three times |
. itself is here and works: daw then . . removes three words, and 3x then . removes three more characters. Only a change that ended in typing is not replayed.
A worked errand
The agent prints Error: cannot open "src/lib/parse.ts" and you want to ask about that file.
Esc— normal mode. Nothing is sent; the agent does not notice./parsethenEnter— the search lands on the match.- Move onto the quoted path, then
yi"— the path is yanked, and on your clipboard. G— back down to the input line.i— you are typing again.- Type your question up to where the path goes, then
Escandpto drop the path in.iagain to carry on typing.
Total: no mouse, no scrollbar, and it works the same on a phone.
Try it
Open a terminal and turn Vim keys on from its long-press menu, then run something with a lot of output — ls -la in a deep folder will do.
- Press
Esc. Watch the NORMAL badge appear, then pressjkto move around. ggto the top of the scrollback,Gback to the bottom./a word you can see,Enter, thenyto yank the match the search just landed on.- Move onto a long filename and press
yiW. Thenwa few times on the same word and count the stops — that is theWlesson. - Move into any block of output and press
yip. pto paste what you copied into the prompt, thenito return to typing.- Type a command with a typo,
Esc,bto the bad word,ciw, and type the correction. - Ask a CLI coding agent something, and mid-turn press
EscEsc— the first press is the mode key, the second is the realEscthat interrupts it.
You now know: in a terminal, Vim navigates, searches and copies everywhere, edits only the line you are typing, and Esc Esc is your way to reach a program that is not listening.
Related
- Vim Mode reference — the full command tables for both halves
- Terminals
- The terminal editor
- CLI Coding Agents
- The phone key row
← Lesson 5 — Search, Yank, Registers and Marks · Lesson 7 — Vim on a Phone →