Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 779
barej Avatar asked Feb 07 '15 08:02

barej


2 Answers

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.
like image 146
gwenzek Avatar answered Oct 18 '22 13:10

gwenzek


You could use regex to find patters matching the regex you give. Design the regex according to match your.

You can give regex by turning on the 'Regular Expression' flag

By this way you can search without comments

Example

You can have this regex to match your case if you want to match alone in single line comments.

^(?!\/\/)([^\/\n]*)YOUR_SEARCH_TERM

If you want to match also in multi line comments use this.

^(?!(\/\/|(\/\*(.|\n)*([^\*])(?=\/))))YOUR_SEARCH_TERM
like image 24
Prasanna Rkv Avatar answered Oct 18 '22 14:10

Prasanna Rkv