PracticalVim Tip92 - yszheda/wiki GitHub Wiki

Table of Contents

Tip 92: Repeat the Previous Substitute Command

Return to the top: <>

Repeat a Line-Wise Substitution Across the Entire File

  • repeat the command across the entire file just by pressing `g&`
  • equivalent to: repeat the last substitute command using the same flags, the same replacement string, and the current search pattern, but use the `%` range.

References:

Amend the Range of a Substitute Command

  • `gv` command enables Visual mode and rehighlights the last selection.
  • `:&&`
* First `&` forms the `:&` Ex command, which repeats the last `:substitute` command.

References:

* Second `&` indicates that the flags from the previous :s command should be reused.

Discussion

  • `&` command is a synonym for `:s`, which repeats the last substitution.
  • `:&&`: acts on the current line
  • `:'<,'>&&` acts on the visual selection
  • `:%&&` acts on the entire file.
  • `g&` is a shortcut for `:%&&`

Fixing the & Command

preserves flags for the `&` command:

⚠️ **GitHub.com Fallback** ⚠️