Click to See Complete Forum and Search --> : Search for string in VI


OhLordy
04-25-2003, 06:50 AM
I'm using VIM 6.1.165 and am trying to search through the document I'm viewing for a particular string.
I have looked through the help and found a command called search of the syntax
search({regex}[, {flags}])
however when I try to use it I keep getting the error message

Not an editor command: search('display_name')

Does anyone know why this might be happening and how to solve it.
Or prehapse a different command that I would be able to search through a document with.

Thank you in advance
Rob

chrism01
04-25-2003, 07:24 AM
Try this vi cmd in cmd mode
/string_to_srch_for

then
n
for next match
?
for reverse direction match ie 'n' backwards

OhLordy
04-25-2003, 07:53 AM
thank you that works brilliantly
:D
Rob

goon12
04-25-2003, 08:01 AM
If you want to replace the string throughout the document you can do this ( in escape mode )

:g/stringtofind/s//replacestring


-goon12

chrism01
04-27-2003, 09:07 AM
To replace all occurences on a given line, go to that line then:
:s/strtofind/replacestr/g

To replace all occurences on all lines, go to line 1 then:
:.,$s/strtofind/replacestr/g

To replace all occurences within a given line range, go to that line then:
:n1,n2s/strtofind/replacestr/g
where n1, n2 are start, end line nums.

Use ctrl-G to get line num of current line.