Sublime Forum

Close all tabs where a regex find a string in the text

#1

Hello,

how can I close all tabs where a string is found in the text with a regex?
Do I need to write my own python plugin or is there a simple solution with a small python line of code or somethign else?

Example:

  1. I open sublime from command line with many files (tabs).
  2. Now I have to close all tabs where a string ‘closethis’ is in the text.

In real the ‘closethis’ string is a more complex regex!

Best regards
Marten

0 Likes

#2

Must be something like (not tested):

import sublime
import sublime_plugin

class CloseViewsByRegexpCommand(sublime_plugin.WindowCommand):
    def run(self, closeregexp):
        for view in [view for view in self.window.views() if view.find(closeregexp, 0)]:
            view.close()

Create a plugin with this code and add a keybinding to call the close_views_by_regexp command with your search string (closethis) as argument.

0 Likes