- All lines in the file.
- line 1 to 30
- line 5 to last line
- This can be plain text and also regular expression. Combining regular expression and this command, replacing words in vi, will be powerful.
- This will get the exact match, not all contained word.
This is his bag : %s/his/her/g => Ther is her bag
Above command changes This also because it contains “his”.
This is his bag : %s/\<his\>/her/g => This is her bag
- Confirm each substitution
- Replace all occurrence in the line
- If you don’t put, default is just replacing first occurrence.
- Ignore case for the pattern
- Do substitution in N lines from the current position of the cursor
This means change all hi to hello in 4 lines from current line.