Sublime Forum

Limited "find all under"

#1

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.

0 Likes

#2

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

0 Likes

#3

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.

[quote=“sublimator”]
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.[/quote]

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.

0 Likes

#4

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

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

0 Likes