Reputation: 3634
Is there any way to exclude folded code from search. When I search for text and that text appears to be in folded part of the code Sublime always unfolds that code snippet and its annoying. I could not find any settings regarding it.
Upvotes: 1
Views: 115
Reputation: 16085
You can make use of Sublime Text's "Find In Selection" feature - select all the unfolded regions, then open the find panel and perform your search with "in selection" toggled on.
Here is a plugin to do this:
import sublime
import sublime_plugin
class FindInUnfoldedTextCommand(sublime_plugin.TextCommand):
def run(self, edit):
folded_regions = self.view.folded_regions()
self.view.sel().clear()
self.view.sel().add_all(folded_regions)
self.view.run_command('invert_selection')
self.view.window().run_command('show_panel', { "panel": "find", "reverse": False, "in_selection": True })
To set this up:
from the Tools menu -> Developer -> New Plugin...
select the template plugin code and replace it with the above
save it, in the folder ST recommends (Packages/User/
) with a name like find_in_unfolded_text.py
- the filename isn't important, just the extension is.
Open the ST console (View menu -> Show Console)
Type/paste view.run_command('find_in_unfolded_text')
Enter
Enter your search string
Violia! The folded text is ignored.
As an alternative to steps 4 and 5, you can add this new command to the menu, to the command palette, or create a keybinding for it.
Upvotes: 2