There are many ways to search through a file with vi.
I am not going to get to heavy into regular expressions in this document, but will
give
the general syntax and some examples of searches I use often.
/ pattern
Search backwards in the file for pattern.
? pattern
To get the next occurrence of pattern.
n
To get the next occurrence of pattern in reverse direction.
N
.
Last line of file or (end of line depending on how it is used).
$
Entire file or (current file depending on how it is used).
%
Beginning of the line.
^
Escape character.
\
Alternate search delimiter.
-
:1,$s/pattern1/pattern2/g
or
:%s/pattern1/pattern2/g
NOTE: The above will replace all occurrences of the pattern in the file!MAKE SURE THIS IS WHAT YOU WANT!If pattern1 is the word the every occurrence of the will be replaced including
:1,$s/\<pattern1\>/pattern2/g
or
:%s/\<pattern1\>/pattern2/g
:%s/\/u\/test/\/u\/home/g
or
:%s-/u/test-/u/home-g
:'a,'bs/pattern1/pattern2/g
or
:100,200s/pattern1/pattern2/g