Checkpoint: rearrange lines in real files

0 of 3

The technique

Your textVim mode: Normal
Put /orders first, then add /returns below it. Before: /orders/:id / /orders. After: /orders / /returns / /orders/:id.

dd then p swaps two lines. yyp copies a line below itself, so you only change the part that differs.

Keys in this lesson

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

Before this lesson: Copying and moving lines, and the module's repeats.

More about this lesson

Move, copy and delete whole lines in each of three real files, with one more change alongside.

You choose the commands here. dd and p move a line, P puts it above, and yyp copies one so you can change the copy. Each file also has a change that the dot, cgn or Ctrl-v makes quicker. Getting it right matters more than the number of keys.

Example

Before you finish in Normal mode, check the order of the lines and the changes one at a time.

Try without hints first. Open help if you need it.

Guides on this topic

Exercise 1 of 3

0keys

par 45

Put /orders above /orders/:id, and add a /returns route below /orders, like it, with the Returns page. The admin pages aren't ready, so comment out their three routes. You can use any commands.

Your textVim mode: Normal

Make it look like this

import { Account, AdminOrders, AdminProducts, AdminUsers, Home, NotFound, OrderDetail, Orders, Returns } from "./pages";

// React Router tries these in order and uses the first that matches.
export const routes = [
  { path: "/", element: <Home /> },
  { path: "/orders", element: <Orders /> },
  { path: "/returns", element: <Returns /> },
  { path: "/orders/:id", element: <OrderDetail /> },
  { path: "/account", element: <Account /> },
  // { path: "/admin/orders", element: <AdminOrders /> },
  // { path: "/admin/products", element: <AdminProducts /> },
  // { path: "/admin/users", element: <AdminUsers /> },
  { path: "*", element: <NotFound /> },
];

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.