Learning Record: vim substitute the replacement operation

vim alternative instruction:
using: substitute command, the specified character may be replaced by other characters. Usually, we will use the abbreviated form: s, in the following format:

:[range] s/search/replace/[flags] [count]

Which, range is specified range, that is, do replace the line in which, when not indicated range, indicates that only operate on the current line.

 

 

Several commonly used marker replacement operation according to

% Of the entire file

All occurrences of the single line g

i ignore case

c confirm the replacement

It indicates the current line

$ The last line

For example:

The first match from the current row to last row for each row to be replaced with new old

:.,$s/\<old\>/new

 

Each line of the entire file to match all the old will be replaced with new, note: oldschool will be replaced with new

:%s/old/new/g

 

From n1 to n2-line to match all old line to be replaced by new, note: n1, n2 represents the number of rows

:n1,n2s/old/new/g         

 

Cursor line to match all the old will be replaced with new and old to ignore case, and asks whether to replace

:s/old/new/gic

When asked whether to replace (? Replace with Teacher (y / n / a / q / l / ^ E / ^ Y)), you can answer:
the y-Yes: to perform this replacement
n No: to cancel the replacement
a All: perform all substitutions without again asking
q quit: exit without making any changes
l Last: after replacing the current matching point End exit
CTRL-E line up roll
CTRL-Y scroll down line

 

You can also use a specific character as a replacement range. For example, the SQL statement to replace all from FROM equal sign portion semicolons (=) is the inequality (<>): :
/ FROM /, /; / S / = / <> / G

 

# Can be used as a delimiter, whereby the intermediate appear / not as a delimiter

: S # old # new / # replace / first current line old / of new /

 

 

Replace the visualized:

In the visualization mode, first select the replacement range and type: command mode, commands can use s replacement text in the selected range.
A number of replacement

Exact replacement

When searching sig, it will also match more than one word sig, signature, signing and so on. If you want to replace a word exactly, you can use the "\ <" beginning to match a word, and use the "\>" to match the end of a word:
: S / \ <Term \> / the replace / gc

A number of replacement

If you want to word Kang and Kodos are replaced with alien, you can use | be a number of replacement.
:% s / Kang \ | Kodos / alien / gc

 

 

Temporary situation encountered on these later encountered other circumstances in actual operation to add. z-god

 

Guess you like

Origin www.cnblogs.com/z-god/p/12358946.html