Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you search all source code in Vim?

Tags:

grep

vim

When using Vim, and given a directory filled with code (e.g. ~/trunk/) with a number of sub-directories, is there a way to grep/search for instances of text/regexes across the entire source code?

At the moment I use:

:lcd ~/trunk :grep "pattern" *.py */*.py */*/*.py */*/*/*.py 

(Obviously I'm limiting this to Python files, which is a different issue, but it's noteworthy that ideally I'd like to limit the searches to files with specific extensions.)

like image 730
Brian M. Hunt Avatar asked Mar 29 '09 17:03

Brian M. Hunt


People also ask

How do we use grep to search for a pattern in multiple files in vim?

From the root of your project, you can search through all your files recursively from the current directory like so: grep -R '. ad' . The -R flag is telling grep to search recursively.


1 Answers

:vimgrep "pattern" ~/trunk/**/*.py :copen 20 

If you have quite a big project I'd recommend to you to use cscope and vim plugins. Here is one designed to handle big projects: SourceCodeObedience

There is a brief description of how to grep text using SourceCodeObedience.

like image 184
Mykola Golubyev Avatar answered Sep 20 '22 07:09

Mykola Golubyev