I suggest you ...

Give option to search only in uncommented code

When searching for a string in a project's source code, I often find myself wasting time examining lines that have been commented out. it would be useful to offer an option to return only lines that are not commented out, so as not to confuse the results.

295 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    JeffJeff shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →
    RobRob shared a merged idea: Add an option in Find/replace to exclude commented lines  ·   · 

    14 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • Paul ToppingPaul Topping commented  ·   ·  Flag as inappropriate

        Such a feature could also be extended to code included/excluded by the preprocessor given the current intellisense knowledge.

        A nice implementation might also tag search hits as "in comment" and allow one to group hits in search results based on that property.

      • AnonymousAnonymous commented  ·   ·  Flag as inappropriate

        'Use Find References' and 'delete commented code' are (good) solutions to *different* problems. This suggestion is about searching for arbitrary text when you know that the results you want are definitely not in comments or doc-comments. For example, find all "= null" in your code so you can check them. Or find all mentions of "para" (e.g. "firstPara", "lastPara", "Paragraph") without hitting all the <param> entries in your doc comments. Or a bug causes an error message to be reported, "out of memory", so you want to find the code that emitted that text to locate the buggy code - but Find in Files returns 350 matches even though there are only 2 lines of *code* in your codebase that include that text.

      • Campbell WildCampbell Wild commented  ·   ·  Flag as inappropriate

        Where is this "Find References" option? Or do you mean right-click on a variable and Find All References? Because whilst that is useful, there are still many times when you need to search for something that isn't an object, for example, a string value or a line of code.

      • Ben Voigt [Visual C++ MVP]Ben Voigt [Visual C++ MVP] commented  ·   ·  Flag as inappropriate

        Instead of a textual search, use "Find References". That will exclude commented code, remarks in comments, appearances inside quoted strings, and similarly named but unrelated items.

      • Campbell WildCampbell Wild commented  ·   ·  Flag as inappropriate

        I totally agree with this, but it's not just commented out code. Valid comments can quite easily contain the same content as a bit of code you are searching for.

        There really needs to be an option to search in comments, defaulted to off. How often do people actually need to search comments?!

      • Tim BurrisTim Burris commented  ·   ·  Flag as inappropriate

        @Boogaloo: It's obvious in the code view. Colorization does not apply to find results, so especially in the case of multi-line comments, it's not all all obvious whether the line is commented out.

      • Mark HurdMark Hurd commented  ·   ·  Flag as inappropriate

        I think this is a good idea, but it must separately allow/deny single line comments, multi-line comments, XML comments, and, importantly, #IFed out code.

      • QwertieQwertie commented  ·   ·  Flag as inappropriate

        Sometimes I want to search only comments, sometimes only code, sometimes both.

        But I probably search my code 20-40 times every day. I don't want to fiddle with a bunch of radio buttons on every search, especially now that the options are always hidden by default!

        I'd actually like to have two or three hotkeys for different "find modes", with different defaults in the search dialog for each hotkey.

      • BoogalooBoogaloo commented  ·   ·  Flag as inappropriate

        It should be pretty obvious that the code you are looking at is commented out. If not, try changing your "Comment" color to something less like your actual code color.

      • FocuscarFocuscar commented  ·   ·  Flag as inappropriate

        really many users are having this annoying problem of search results including comments too.. -.-"

      • RobRob commented  ·   ·  Flag as inappropriate

        Oftentimes when searching and/or replacing in code, the text I'm searching for exists in both code and comments. An option to exclude comments from search results would save a lot of time.

      Feedback and Knowledge Base