Sublime Forum

Search all open tabs plugin

#1

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]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)[/code]

also add key binding on Default.sublime-keymap under “%appdata%\Sublime Text\Packages\User”

<bindings> ... <binding key="ctrl+alt+f" command="search"/> ... </bindings>

enjoy!

0 Likes

#2

one of the major features this editor miss
thanks !!!

0 Likes

#3

:smile:

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 :sunglasses:

0 Likes

#4

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.

0 Likes

#5

updated on repo

0 Likes

#6

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.
0 Likes