Replacement command of one typeg/pattern/s/old/new/g
FirstGIndicates that an operation is selected,PatternSpecifies the row mode,SIndicates the replacement operation,OldIs the content to be replaced,NewIs new content,
GGlobal replacement:
# Add an arc to the first to ten rows /.*/(&)/
The
& Indicates the search mode ~ Indicates that the replacement text \ U specified in the previous replace command is changed to uppercase \ L to lowercase \ U or \ L and \ e or \ e. all payments until \ e and \ e are in uppercase or lowercase. In addition, in VI, \, ", and | any non-alphanumeric characters other than the delimiter used to replace the command, which is very useful in path replacement.
The following are examples:
# Replace that or this with this or that: % S/\ (that \) or \ (this \) /\ U \ 2 or \ L \ 1/---- # Replace child at the end of the sentence with children: % S/child \([,.;! :?] \)/Children \ 1/G ----# Change Wi-Fi or Wi-Fi to WLAN: G/\ c/s/Wi-Fi/WLAN/g---- # Change MGI/R/abox to MGI/R/asquare: G/Mg \ ([Ira] \) box/S // mg // my \ 1 square/g <=>: g/mg [Ira] box/S/box/square/G ---- # Replace multiple spaces with one space: % S/* // G ---- # use a space to replace one or more spaces after a period or a colon: % S/\ ([:.] \) */\ 1/G ---- # delete all blank rows: G/^ $/D ---- # delete all blank rows and blank rows: g/^ [] [] * $/D ---- # insert two blank spaces at the beginning of each line: % S/^/>/---- # Add at the end of the next 6 rows. :., 5/$ /. /---- # reverse the row order of the file: G /. */m0o <=>: G/^/m0o ---- # search for the starting line that is not a number and move it to the end of the file: G! /^ [0-9]/M $ <=> G/^ [^ 0-9]/M $ ---- # Copy 10 words from lines 12th to 17 of the file to the current end of the file: 1, 10g/^/12, 17 T $ ~~~~ The number of repetitions ---- # Write the content in the second row below the beginning of chapter into the begin file: G/^ chapter /. + 2 W> begin ----:/^ Part2/,/^ Part3/G/^ chapter /. + 2 W> begin ----:/^ Part2/,/^ Part3/G/^ chapter /. + 2 W> begin | + T $