Copy and move text

0 of 2

The technique

Your textVim mode: Normal
Move the first line below the second. Before: milk / eggs / bread. After: eggs / milk / bread.

dd keeps the deleted line, and p puts it below the line the cursor is on now.

Keys in this lesson

yy
Copy the line.
p
Put after the cursor, or below the line.
P
Put before the cursor, or above the line.
yiw
Copy the word.
dd
Delete the line.

Before this lesson: Operators and line boundaries.

More about this lesson

Know where Vim puts a copied line and where it puts a copied word.

y copies, and d deletes and copies. yy and dd work on whole lines, so p puts the line below the current one and P puts it above. A copied word, such as one from yiw, goes after the cursor with p or before it with P. Be careful, because the next delete replaces what p puts.

Example

With the cursor on the first line of a checklist, yy then p puts a copy of it below. dd then p moves the line instead, because dd removes the original.

Use Start over to try again.

Guides on this topic

Exercise 1 of 2

0keys

par 5

Next.js only reads "use client"; on the first line of the file. Move it there.

Your textVim mode: Normal

Make it look like this

"use client";
import { useTransition } from "react";
import { addToCart } from "../cart/actions";

// The Add to cart button on a product page. It needs state, so it runs in the browser.
export function AddToCart({ productId }) {
  const [pending, startTransition] = useTransition();
  return <button disabled={pending} onClick={() => startTransition(() => addToCart(productId))}>Add to cart</button>;
}

Yours

Par

Keyboard shortcuts
Ctrl+Enter
Check the result
Ctrl+Alt+U
Undo the last change
Ctrl+Alt+H
Show the next hint
Ctrl+Alt+R
Start the exercise over
Ctrl+Alt+P
Previous exercise
Ctrl+Alt+N
Next exercise
Ctrl+Alt+K⌃⌥K
Show the keyboard shortcuts
Ctrl+Alt+F⌃⌥F
Turn focus mode on or off
Ctrl+Alt+S⌃⌥S
Open the editor settings
Enter
Go on to the next step after you finish

The Ctrl+Alt shortcuts don't clash with Vim's own keys. On a Mac, use Control and Option.