Search for text in vi or vim
vi and vim have powerful searching capabilities because they bring to bear the richness of regular expressions.
To search for the next occurence of the text ‘maybe’ from the current cursor position, type:
/maybe
Search backward from the current position by using ? instead of / in the command.
Once you have searched for something, you can find the next occurrence by pressing n or the previous occurrence with N.
Searching in vi/vim is enhanced with regular expressions. For example, to find the next occurence of the text ‘Total’ that occurs at the beginning of a line, use:
/^Total









Boris said on October 10, 2008
And how do I unmark the text? It’s always highlighted..
Quinn McHenry said on October 10, 2008
I bet there is a slick way to do that, but I honestly don’t know that way. My technique is to search for something else that doesn’t exist in the file..
/jkdsjklsd
will do the trick. If someone else knows the guru way, please let us know! I’d love to know how, too.
Anonymous said on October 13, 2008
:nohl
Arturo said on January 12, 2011
dear god, thank you anonymous. ‘yank’ is erratic as f*ck when the search words are highlighted.
Arturo said on January 12, 2011
nevermind. maybe i need to restart terminal or something because yank and put are not adhering to any type of logic whatsoever.
gesty said on February 7, 2011
sometimes it has issues with where your cursors is compared to where you are working in the text.
Kevin said on October 20, 2011
the full command would be :no hlsearch which can be abbreviated to :nohls, set !hls, set nohls, set hlsearch!. And you can use set hls or set hlsearch to turn the highlighting back on.