Home Download Buy Blog Forum Support

search all open tabs plugin

search all open tabs plugin

Postby vim on Tue Dec 23, 2008 6:51 am

I have made another plugin, which search all open buffers on sublime (all opened tabs) for a pattern. the pattern used is taken from the clipboard. i.e. you need to first select and copy a text, then start the search with the desired keyboard shortcut (ctrl+alt+f on this example). i would have used better input system, but i couldn't find any (suggestions/changes are welcomed)

you can find this plugin (always updated) for download at the community repository or, do the following :
1. make a new file named: Search.py under "%appdata%\Sublime Text\Packages\User", which contains:
Code: Select all
import sublime, sublimeplugin

class SearchCommand(sublimeplugin.TextCommand):
   def run(self, view, args):
      failesafe = 1000
      counter = 0
      result = []
      files_i_have_been = []
      view_list = view.window().views()

      selection = view.sel()[0]
      if selection.begin() - selection.end() != 0:
         pattern = view.substr(selection)
      else:
         pattern = sublime.getClipboard()
     
      for a_view in view_list:
         # avoid re-searching same view (if opened twice)
         if a_view.fileName() in files_i_have_been:
            continue
         else: 
            files_i_have_been.append(a_view.fileName())
         
         # search   
         next_region = view.line(0) # start from 0
         while next_region is not False:
            region = a_view.find(pattern, next_region.begin(), 0)
            if region is not None:
               (row, col) = a_view.rowcol(region.begin())
               s = a_view.substr(a_view.line(region))
               full_s = a_view.fileName() + "<" + str(row+1) + "> " + s
               result.append(full_s)
               next_region = self.advance_line(a_view, region)
            else:
               break
           
            counter += 1
            if counter > failesafe:
               break
           
      view.window().showQuickPanel("", "searchRebound", result) 
      #for line in result:
      #   print line
     
   def isEnabled(self, view, args):
      if view.fileName() is not None:
         return True
      else:
         return False
   
   def advance_line(self, view, last_region):
      (row, col) = view.rowcol(last_region.begin())
      next_point = view.textPoint(row+1, 0)
      next_region = view.line(next_point)
     
      if next_region.begin() > last_region.end():
         return next_region
      else:
         return False

class SearchReboundCommand(sublimeplugin.TextCommand):
   def run(self, view, args):
      (file_and_line, sep, line_content) = args[0].partition(">")
      (file, sep, row) = file_and_line.rpartition("<")
     
      view_list = view.window().views()
      for a_view in view_list:
         print "|" + file + "|" + a_view.fileName() + "|"
         if file == a_view.fileName():
            view.window().focusView(a_view)
            position = a_view.textPoint(int(row), 0)
            a_view.show(position)


also add key binding on Default.sublime-keymap under "%appdata%\Sublime Text\Packages\User"
Code: Select all
<bindings>
...
   <binding key="ctrl+alt+f" command="search"/>
...
</bindings>


enjoy!
Last edited by vim on Tue Dec 23, 2008 5:31 pm, edited 4 times in total.
vim
 
Posts: 298
Joined: Tue May 27, 2008 6:51 pm

Re: search all open tabs plugin

Postby Silvester on Tue Dec 23, 2008 8:10 am

one of the major features this editor miss
thanks !!!
Silvester
 
Posts: 1
Joined: Tue Dec 23, 2008 8:08 am

Re: search all open tabs plugin

Postby vim on Tue Dec 23, 2008 8:13 am

:)

i also think that the quick panel results can be interactive, i.e. you can click them and get to the right location. if anyone know something about how to do it, you are welcome.

EDIT: done, and updated 8-)
vim
 
Posts: 298
Joined: Tue May 27, 2008 6:51 pm

Re: search all open tabs plugin

Postby vim on Tue Dec 23, 2008 1:07 pm

another improvement, it now search for the selected text on current view (no need to copy it before). if no selection exists it will use the clipboard content as the pattern.

EDIT: use the community repo, for latest including all the fixes (fixed some bugs since it was released).the link for the repo is at the first post.
vim
 
Posts: 298
Joined: Tue May 27, 2008 6:51 pm

Re: search all open tabs plugin

Postby vim on Mon Feb 16, 2009 6:42 am

updated on repo
vim
 
Posts: 298
Joined: Tue May 27, 2008 6:51 pm

Search In Open Views

Postby vim on Fri Nov 13, 2009 10:25 pm

Search In Open Views
allows you to search any term on all your open files (views)

download from sublimewiki

changes:
* revised the whole selection process, now uses an input bar.
* after selecting the desired file/loaction the searched term will be marked rather than the whole line.
vim
 
Posts: 298
Joined: Tue May 27, 2008 6:51 pm


Return to Plugin Announcements

Who is online

Users browsing this forum: Yahoo [Bot] and 12 guests