How to do a grep-like search through multiple files in Eclipse/CDT
I read a lot of code written by other people and need to trace variables, function calls, include files, etc. so I've been doing a lot of grepping (e.g. "grep variablename *") for variable and function names in my directory of c and h files. Then I'll open the file, find the search term and then grep again for a new search term. I actually wrote a code browser for a previous project in Perl (in the days before I converted to Python). It worked well, but it was not robust enough for a generic C project. I tried various tools including Red Hat's Source Navigator, Wind River's Sniff+, and Understand for C/C++. They were good tools, but they didn't do exactly what I wanted-- which was to trace through multiple source files quickly looking for a given search term. I was about to start rewriting my code browser tool using bison/flex or maybe PLY, when I decided to try Eclipse.
Suprisingly, Eclipse met my needs satisfactorily. Using the "Find Text in Project" command and a custom key binding, I may have a significantly minimized my use of the grep command. I am able to select a variable name in a source file, then press CTRL+G, and Eclipse gives a list of all files containing that variable. Double-clicking a file opens it with all the search terms highlighted in a tasteful purple color. Clicking the up and down arrows in the search window navigates me through all the occurrences in the files. I know this doesn't seem like a big deal, but it's the first time I've found this capability to work to my liking. (Admittedly, I have not tried all the tools. I'm sure Emacs users would be especially unimpressed.)
Here are the steps:
Suprisingly, Eclipse met my needs satisfactorily. Using the "Find Text in Project" command and a custom key binding, I may have a significantly minimized my use of the grep command. I am able to select a variable name in a source file, then press CTRL+G, and Eclipse gives a list of all files containing that variable. Double-clicking a file opens it with all the search terms highlighted in a tasteful purple color. Clicking the up and down arrows in the search window navigates me through all the occurrences in the files. I know this doesn't seem like a big deal, but it's the first time I've found this capability to work to my liking. (Admittedly, I have not tried all the tools. I'm sure Emacs users would be especially unimpressed.)
Here are the steps:
- Set up an Eclipse 3.2 / CDT 3.1 project. If you don't need to do any building, you can use these instructions from my previous post.
- Set up a custom key binding for the "Find Text in Project" command
- Go to "Window" -> "Preferences..." -> "General" -> "Keys"
- Click on the "Modify" tab
- In the "Command": "Category:" dropdown, select "Search"
- In the "Command": "Name:" dropdown, select "Find Text in Project"
- In the "Key Sequence": "Name:" box, press CTRL+G
- Click the "Add" button
- Click "OK"
- In a source file, select some text and press CTRL+G
- In the search window, double-click a file or click the up or down arrows
1
Comment
—
Comments feed for this post
Post a comment
About
I'm Eliot and this is my notepad for programming topics such as Python, Django, Ubuntu, Emacs, etc... more »
Search Blog
Tags
-
algorithms
(4)
-
aws
(8)
-
blogproject
(20)
-
c_cplusplus
(12)
-
cardstore
(8)
-
colinux
(2)
-
concurrency
(9)
-
conkeror
(2)
-
cygwin
(18)
-
datastructures
(15)
-
datetime
(3)
-
dell
(3)
-
django
(39)
-
emacs
(20)
-
files_directories
(10)
-
install_setup
(7)
-
javascript
(3)
-
keyboard
(6)
-
matplotlib
(5)
-
mercurial
(4)
-
nginx
(2)
-
preferences
(8)
-
processes
(3)
-
pyqt
(18)
-
python
(122)
-
ratpoison
(3)
-
regexes
(5)
-
rsync
(3)
-
softwaretools
(17)
-
sql
(13)
-
ssh
(7)
-
subversion
(6)
-
twisted
(6)
-
ubuntu
(60)
-
urxvt
(5)
-
vxworks
(25)
-
webservices
(4)
-
wmii
(7)
Blogroll
- Adam Gomaa
- Alex Clemesha
- Amir Salihefendic
- Armin Ronacher
- David Beazley
- David Ziegler
- Duncan McGreggor
- Gareth Rushgrave
- Glyph Lefkowitz
- Guido van Rossum
- Ian Bicking
- Jacob Kaplan-Moss
- James Bennett
- James Tauber
- Jesper Noehr
- Matt Harrison
- Nikolay Kolev
- Parand Darugar
- Peter Baumgartner
- Peter Bengtsson
- Rob Hudson
- Simon Willison
- Will McGugan
#1 Emilio Monti commented on 2008-05-15:
You could also like to highlight your grep patterns on the current
edited file (Google Toolbar-like) with the following plugin:
SimpleSearch