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 editorsTerminals & CLI agents
Motions, counts, text objects
Search, yank, registers, marks
d c x r s D Canywhere in the fileonly 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: dd clears 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 dd clears 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:

  1. the cursor is on the line you are typing, and
  2. 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 than x.

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:

  1. Esc from insert mode → normal mode. Nothing is sent.
  2. Esc again from normal mode → a real Esc goes 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. yip takes the block your cursor is standing in, and when you press Esc the cursor is still down at the prompt, so it would take your own input box instead. Esc, then k a few times or { to step up into the reply, then yip.
  • yi" — lift the path out of cannot open "src/lib/parse.ts".
  • yiW — copy a URL. Remember W over w: a URL is one W but seven ws.
  • gx or Enter — 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 availableWhat to do instead
u — no undoGet back to typing and use your shell's own undo, Ctrl_ in bash and zsh
Editing above your input lineCopy it instead — yy, yiw, yip all work up there
Editing while something is runningWait for it to finish. Reading and copying carry on working
d or c across output rowsOnly the line you are typing can change — across as many rows as the terminal wrapped it onto
dipyip — copying a block is almost always what you meant
Visual block, CtrlVV for whole lines
: commandsNothing to substitute in — this is a prompt, not a file
. after a change that ended in typingRetype 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.

  1. Esc — normal mode. Nothing is sent; the agent does not notice.
  2. /parse then Enter — the search lands on the match.
  3. Move onto the quoted path, then yi" — the path is yanked, and on your clipboard.
  4. G — back down to the input line.
  5. i — you are typing again.
  6. Type your question up to where the path goes, then Esc and p to drop the path in. i again 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.

  1. Press Esc. Watch the NORMAL badge appear, then press j k to move around.
  2. gg to the top of the scrollback, G back to the bottom.
  3. / a word you can see, Enter, then y to yank the match the search just landed on.
  4. Move onto a long filename and press yiW. Then w a few times on the same word and count the stops — that is the W lesson.
  5. Move into any block of output and press yip.
  6. p to paste what you copied into the prompt, then i to return to typing.
  7. Type a command with a typo, Esc, b to the bad word, ciw, and type the correction.
  8. Ask a CLI coding agent something, and mid-turn press Esc Esc — the first press is the mode key, the second is the real Esc that 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.

Lesson 5 — Search, Yank, Registers and Marks · Lesson 7 — Vim on a Phone