Normal Mode (6) – Replace Phrase
![Replacing Phrases in Vim Editor Normal Mode](/_next/image/?url=https%3A%2F%2Fstatic.d-libro.com%2F01-course-content-images%2F2011-10-Linux-Introduction%2F010-main-figures%2Fnormal-mode-6-replace-phrase-id201110030810.webp&w=1920&q=75)
In Normal mode, you can search for a phrase and replace it with a new phrase using the command below.
:[search area]s/[search phrase]/[replace phrase]/option
Search area
%
: you can search and replace a phrase in the entire document
n
: you can search and replace a phrase under line n
Option
g
: you can replace all phrases in the selected search area. If you select the entire document, option g is the default setting.
c
: you can make confirmations for replacement one by one
Examples
Replace the first A with B in line 3 (no confirmation)
:3s/A/B
Replace all A with B in line 3 (no confirmation)
:3s/A/B/g
Replace all A with B in line 3 (one-by-one confirmation)
:3s/A/B/gc
Replace all A with B in the entire document (no confirmation)
:%s/A/B/g
Replace all A with B in the entire document (one-by-one confirmation)
:%s/A/B/gc