Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I search in Visual Studio and get it to ignore what is commented out?

I am refactoring a C++ codebase in Visual Studio 2005. I'm about half way through this process now and I've commented out a lot of old code and replaced or moved it. Now I'm searching to see that I have to change next but the search function keeps bringing me the old commented out stuff I no longer care about. I don't really want to delete that old code yet, just in case.

Is there any way I can search all files in the solution and get results ignoring what is commented out? I don't see a way in visual studio itself, is the perhaps a plug-in that would do it?

like image 537
RD. Avatar asked Jan 28 '10 10:01

RD.


People also ask

How do I find commented codes in Visual Studio?

In the visual studio. Select View->Task list. There would be a drop down at the top of the talk list window where you can select Comments. This would show all the comments in the solution.

How do I search for content in Visual Studio?

The new experience is available by searching for “Find in Files” or “Replace in Files” in Visual Studio search (Ctrl+Q by default). You can also get to these commands with Ctrl+Shift+F and Ctrl+Shift+H respectively.

How do I search for a word in an entire project in Visual Studio?

To use Incremental Search, just press Ctrl+I and start typing. Your search term will appear in the status bar at the bottom of the screen and your search will update as you type. Press Ctrl+I again to move to the next result and Enter or Escape to end the search.


2 Answers

As the other provided solutions didn't work for me, I finally discovered the following solution:

^~(:b*//).*your_search_term

Short explanation:

  • ^ from beginning of line
  • ~( NOT the following
  • :b* any number of white spaces, followed by
  • // the comment start
  • ) end of NOT
  • .* any character may appear before
  • your_search_term your search term :-)

Obviouly this will only work for // and ///-style comments.

You must click "Use Regular Expressions " Button (dot and asterisk) on your find window to apply regex search

like image 171
rboehme Avatar answered Oct 27 '22 00:10

rboehme


My take:

yes you can use regular expressions, those tend to be too slow and thinking about them distracts from focusing on real stuff - your software.

I prefer non-obtrusive semi-inteligent methods:

Poor man's method: Find references if you happen to use intelisense on

Or even better: Visual assist and it's colored "Find all References" and "Go To" mapped to handy shortcuts. This speeds up navigation tremendously.

like image 43
MaR Avatar answered Oct 26 '22 23:10

MaR