Swapping via regular expressions is performed by the ex command
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:
Or you can use a relative location using
-/+. To swap only on a line two above the cursor:
Range can also be defined by using visual mode to select the area to perform the search. Visually select a region and press
Ranges can also be absolute or relative
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.
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