Search for text in vi or vim

Contributor Icon Contributed by Rex Date Icon November 10, 2003  
Tag Icon Tagged: UNIX

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

Previous recipe | Next recipe |
 
  • Boris
    And how do I unmark the text? It's always highlighted..
  • 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
    :nohl
blog comments powered by Disqus