VI editor find and replace

1. Search under Vi

In VI command mode: Enter "/word to search" and press Enter to enter the search. You can press "n" to search for the next one, and "N" to search for the previous one.
Similar to the search command "?" and "/", the difference is that "/" is a downward search, and "?" is an upward search.

2. Substitute in Vi
In the last line mode of VI, enter ":" to replace.

Like this example:

:s/text1/text2 is used to replace the first "text1" found in the paragraph where the cursor is searched with "text2";

:s/text1/text2/g is used to replace all "text1" in the paragraph where the cursor is located with "text2";

:m,ns/text1/text2/g is used to replace all searched "text1" with "text2" starting from m line to the end of n line. You can use $ to indicate the last line, that is, "1,$" to replace all qualified characters in the document.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325024656&siteId=291194637