Vim and vim Official Website
When performing simple global search replacement, you can use the following ex command:
: % S/which/what/g
It is easy to use
% |
Each row (everyline) |
S |
Replace (substitue) |
Which |
Search content |
What |
Replaced content |
G |
Global on that line) |
In this way, you can quickly implement the global search and replacement function, but sometimes we do not want to complete all the replacement operations at a time, it is possible that we only want to replace a part.
To implement this operation, we first think of the execution sequence as search-> modify? -> Modify-> Find Next-> modify? -> Modify.
The specific commands can be executed in the following order:
/Which |
Search |
Cwwhat [ESC] |
Chang word |
N |
Next, no need to replace |
N |
Proceed to the next step and modify it. |
. |
. (Dot) is used to repeat the previous operation, that isCwwhat [ESC] |
Vim SEARCH Command
In command mode, press '/' and Enter the character to be searched, Enter .? The difference with/is that a forward (down) lookup and a backward (up ).
In addition, '*' can be used to find the word under the current cursor (exact match), while 'g *' can partially match. Replacing '#' with '* Indicates searching backward (up.
Vim SEARCH Command
In command mode, press '/' and Enter the character to be searched, Enter .? The difference with/is that a forward (down) lookup and a backward (up ).
In addition, '*' can be used to find the word under the current cursor (exact match), while 'g *' can partially match. Replacing '#' with '* Indicates searching backward (up.