Search code examples
commentssublimetext2sublimetext3sublimetext

Sublime Text - Exclude comments in search


Every time I search for a function inside of hundreds of files, I see so many matches for comments which have no effect in the code.

Can someone limit Sublime Text's search scope to real code, and exclude comments?

I use Sublime Text 3 for developing a C++ program.


Solution

  • I created a Plugin that search for a given string inside a given scope. The default scope selector is -comment effectively searching outside of comments. The text to search for is taken from the current selection. The results are presented in the drop-down menu

    Basically I combined two API methods:

    • view.find_all(pattern) that searches for a pattern in the given view.
    • view.match_selector(position, scope_selecor) that check if the given position is inside the given scope.