How do I find and replace in Vim?
- User
How do I find and replace in Vim?
Assistant
In Vim, you can find and replace text using the substitute command. Here's how:
Basic find and replace:
:%s/old/new/g%- applies to the entire files- substitute commandold- text to findnew- replacement textg- global flag (replaces all occurrences on each line)
Common variations:
Without the
gflag - replaces only the first occurrence on each line::%s/old/new/Current line only:
:s/old/new/gSpecific line range (e.g., lines 5-10):
:5,10s/old/new/g
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.