normal·mode
~ / ex / global-and-sortlesson 5/7

Matching lines: :g, :v and :sort

Run a command on every line that matches (or doesn't), and sort lines.

4 drills

  1. Delete the noise: Delete every line that the target no longer has, with one :g/pattern/d. Pick a short pattern that only those lines contain.
  2. Keep only the matches: Keep only the lines that match a pattern and delete all the others, with :v/pattern/d.
  3. Move and copy with :g: Combine :g with :m or :t to rearrange lines: :g/^/m0 reverses the file, :g/pat/m$ moves matches to the end, :g/pat/t$ copies them there.
  4. Sort lines: Sort the lines into the order of the target with :sort and the right flag, if any: u (unique), n (by number) or ! (reverse).

The drill editor loads in your browser.

outside the editor the page is in normal mode: ? keymaps · / find · : commandsfound this useful? ☕ support it ·credits · source · not affiliated with Vim or Neovim