Home Download Buy Blog Forum Support

Limited "find all under"

Limited "find all under"

Postby DSHugo on Fri Sep 30, 2011 9:30 pm

Currently, "alt+f3" runs the `find_all_under` command, which selects all the occurrences of the already highlighted word in a document -- ready to be replaced, if one types in something. I wonder if it is possible to limit the scope of this kind of selection.
The thing I wanted it for, is to be able to replace some word in a part of the document, pretty much like "find & replace + in selection", but with a nice preview (highlighting) of what is going to get altered, and the ability to adjust it. Currently, I'd have to select a block of text with a mouse, hit ctrl+f, type in the word and preview what's got highlighted. Then, if I'm satisfied with the intermediate result, I'd hit ctrl+h, type in the replacement, and the job is done. However, if too much gets highlighted in the first step, I have no way to adjust: ctrl+f just finds the words, but does not select them to make use of ST2 multiple selection feature. If words were actually selected, I'd just add/remove a few selections with a mouse, and then type in my replacement. I'd use ctrl+d, but its direction seems odd sometimes, and requires numerous key-presses.
DSHugo
 
Posts: 42
Joined: Tue Sep 20, 2011 11:05 am

Re: Limited "find all under"

Postby jps on Sat Oct 01, 2011 12:08 am

You can use Find All in the find panel, while limiting the scope to the selection
jps
Site Admin
 
Posts: 3067
Joined: Wed Mar 19, 2008 12:33 pm

Re: Limited "find all under"

Postby DSHugo on Sat Oct 01, 2011 7:58 am

jps wrote:You can use Find All in the find panel, while limiting the scope to the selection

I didn't actually realize that "find all" does indeed not only highlight the results, but actually select them -- I misinterpreted the visual hints. At the first glance it looked like you misread my question, but it appears I now have the answer for my question, thank you. A shame I didn't find it myself.

sublimator wrote:Something like that? Outline of the area the search all under is restricted to?

There used to be a SearchInArea plugin for ST1 but it's not released.

Yeah, exactly like this. What's on the image of yours -- is it ST1 with the SearchInArea you mentioned?

I have, however, got a related question: is there a counterpart of "center selection": the "center next selection"? Just for the case when "find all" selects several screens worth of stuff, to have an easy way to navigate through what's got selected.
DSHugo
 
Posts: 42
Joined: Tue Sep 20, 2011 11:05 am

Re: Limited "find all under"

Postby DSHugo on Sat Oct 01, 2011 3:27 pm

sublimator wrote:I don't think there is a `center next selection` though it's an interesting idea and could be easily done with a plugin.


It came up this way (in case someone finds it useful), though obviously lacking in proper visual hinting of which element is active:
Code: Select all
import sublime, sublime_plugin

selection = {
   "hash": 0,
   "pos": 0
}
def getNextPos(self):
   if len(self.view.sel()) == 1:
      return 0
   currHash = ','.join(map(str, self.view.sel())).__hash__()
   if selection['hash'] != currHash:
      selection['hash'] = currHash
      selection['pos'] = 0
   pos = selection['pos'] % len(self.view.sel())
   selection['pos'] += 1
   return pos

class CenterNextSelCommand(sublime_plugin.TextCommand):
   def run(self, edit):
      self.view.show_at_center(self.view.sel()[getNextPos(self)])
      #self.view.show(self.view.sel()[getNextPos(self)])
DSHugo
 
Posts: 42
Joined: Tue Sep 20, 2011 11:05 am


Return to General Discussion

Who is online

Users browsing this forum: danpyq, Exabot [Bot] and 24 guests