Copy and move text
The technique
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 5Next.js only reads "use client"; on the first line of the file. Move it there.
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>; }