One, string lookup
1. Using/And in Vim to find a string, the difference is that
/string highlights the first string that matches the cursor after the carriage return, and the cursor moves to the first letter of the string;
? string highlights the first match before the cursor A string that returns the first letter of the string after the cursor moves to it.
After carriage return, press N to go to the next matching string in the same direction, and press N to go in the opposite direction to the previous matching string.
2. Use the command: Set IC and: Set Noic to set the lookup without distinction and case sensitivity, respectively.
If you look for special characters, such as ^, $, *,/and., you need to escape by adding \ in front.
Second, string substitution
1. Vim can be used: s command to replace a string, as follows:
: s/str1/str2/Replace the current line the first str1 is STR2
: s/str1/str2/g Replace all str1 in the current line as St R2
: m,ns/str1/str2/replaces the nth line start to the last row in the first str1 of each row is STR2
: m,ns/str1/str2/g replaces the nth line start to the last row in all str1 as str2
(note: M and n As a number, if M is., which indicates the start of the current line; If n is $, it is the end of the last line)
If # is used as a delimiter, the middle/not as a delimiter, for example:
: s#str1/#str2/# Replace the current row the first str1/is str2/
:%s+/oradata/apras/+/user01/apras1+ (use + to replace/):/oradata/apras/replaced with/user01/apras1/
2. Other
:%s/str1/str2/(equivalent to: g /str1/s//str2/) Replace the first str1 of each line with the STR2
:%s/str1/str2/g (equivalent to: g/str1/s//str2/g and: 1,$ s/str1/str2/g) Replace all str1 in the text str2 The
can be seen from the Replace command, where G is placed at the end of the command to replace each occurrence of the search string, without G, to replace only the first occurrence of the search
string, and G at the beginning of the command to replace all rows in the body that contain the search string.
3. return line break \ n
:%s/\\n/str/g
:%s/str/\\n/g
Replace \\n Even if using the Gedit tool (represents the carriage return line break \ n)
4. For example:
Replace all/n to \ n in the document
:%s#/n#\\n#g
Vim Find and Replace commands replace/n and \ n