Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you list the matches of Vim's search?

Tags:

vim

search

I would like to list the matches, when I hit:

/example 

so that I see where all matches are at once.

like image 510
Léo Léopold Hertz 준영 Avatar asked Feb 04 '09 00:02

Léo Léopold Hertz 준영


People also ask

How do we search forwards for a pattern?

In normal mode you can search forwards by pressing / (or <kDivide> ) then typing your search pattern. Press Esc to cancel or press Enter to perform the search. Then press n to search forwards for the next occurrence, or N to search backwards.

How do we search forwards for a pattern in vim?

One can search forward in vim/vi by pressing / and then typing your search pattern/word. To search backward in vi/vim by pressing ? and then typing your search pattern/word. Once word found in vim, you can press the n key to go directly to the next occurrence of the word in backwards.

How do I search for a file in vim?

Vim offers several commands for searching for files by name: :find, :sfind, :tabfind on the command-line, several normal-mode commands like gf, and others. If you just enter :find filename , Vim will directly open the first file found in your 'path' matching "filename".


2 Answers

:g//p 

In its longer form:

:global/regular-expression/print 

You can leave out the pattern/regex and Vim will re-use the previous search term.

Trivia: The grep tool was named after this command sequence.

like image 125
too much php Avatar answered Sep 20 '22 18:09

too much php


You can also do a :

g/pattern/#

that will print the pattern you want and the number of the line.

like image 34
Taurus Olson Avatar answered Sep 22 '22 18:09

Taurus Olson