Tip 108: Call grep Without Leaving Vim
Return to the top: <<Practical Vim>>
Using grep from the Command Line
For example:
$ grep -n Waldo * department-store.txt:1:Waldo is beside the boot counter. goldrush.txt:6:Waldo is studying his clipboard. goldrush.txt:9:The penny farthing is 10 paces ahead of Waldo.
-
-n
: include the line number in the printed output. - specify line number in vim:
e.g.
# open goldrush.txt at line 9 $ vim goldrush.txt +9
Calling grep from Inside Vim
References:
# If you open the file in vim, # then you can \"ayy@a the next line to execute the vim command: :h :grep
For example:
:grep Waldo *
- Vim parses the result and builds a quickfix list from them.
-
We can navigate through the result by
:cnext
/:cprev
-
Vim automatically include the
-n
flag.