vim替换的几个前缀定位参数


Swapping via regular expressions is performed by the ex command, 替换通过正则表达式执行通过 ex 命令
:{range}s/pattern/string/{flags} {count}

如果你想替换指定行,你需要提供这一行的绝对定位,也就是第几行。
a specific line  =  2s 

If you wish to replace instances of a work on a specific line you can supply the exact line with the absolute location. To swap matches only on line 2:
:2s/Seconds/time

Or you can use a relative location using -/+. To swap only on a line two above the cursor:
光标的前的第2行
:-2s/Seconds/time

Range can also be defined by using visual mode to select the area to perform the search. Visually select a region and press :
范围
:'<,'>s/Second/time

Ranges can also be absolute or relative
2-4行
光标前2 到后2行
:2,4s/Second/time
:-2,+2s/Second/time

The first does lines 2 through 4 and the second does 2 lines above the cursor to two lines below the cursor.

全部  就是  %
If you want to swap all cases you can supply the range and the flag g which finds all matches. Supply the % range for the entire document.
:%s/Seconds/time/g

Some commonly used flags are:
  • c: Confirms each substitution (yes/no/abort/quit)
  • g: Replace all occurrences in a line. Without this flag only the first instance on a line is swapped.
  • i: Ignore the case of the pattern
  • I: DO NOT ignore the case of the pattern
For further information check out the built in help :h :substitute.
阅读量: 371
发布于:
修改于: