normal·mode
~ / ex / substitutelesson 4/7

Substitute: :s, ranges and flags

Replace text on a line, in a range or everywhere, with & for the whole match.

4 drills

  1. Every match on this line: Replace every occurrence on the cursor line, and only on that line, with one :s command. Don't forget the flag that means "all of them".
  2. The whole file: Make the replacement on every line of the file with one :%s command.
  3. Just one part of the file: Only the paragraph with the cursor should change. Select it with vip and press : so the substitution gets the '<,'> range.
  4. Reuse the match with &: Change every match in the file using & in the replacement to stand for the matched text (or \& for a literal ampersand).

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