« Remove Files By Inode Number (Linux/UNIX/Mac OS X) // More Florida Schools Directory/Search Services Just Launched! »
vi Search and Replace
Posted on June 20th, 2008 by Basil
It’s sad to say I don’t use the vi search & replace enough to have it ingrained where it should be, so here’s to open documentation:
Adding the “how to” search for those who might need it:
Note: Search wraps around at end of file
To search STR forward: /STR
To search STR backwards: ?STR
To repeat the search: n
To repeat search in opposite direction: N ([SHIFT]-n)
Replace
Replace: Same as with sed, Replace OLD with NEW:
First occurrence on current line: :s/OLD/NEW
Globally (all) on current line: :s/OLD/NEW/g
Between two line numbers #,#: :#,#s/OLD/NEW/g
Every occurrence in file: :%s/OLD/NEW/g
Discussion Area - Leave a Comment