Sublime Forum

Option "find_selected_text" doesn't work in incremental find

#1

Dear all,

I’m a new Sublime Text user switching from Emacs. I prefer using incremental find because it is closer to the search behavior I’m familiar with. However, I found that, when using incremental find, current selected text doesn’t appear in find box although option “find_selected_text” set to true. On the other hand, normal find works as expected at the same time.
I’ve searched this forum but only find one marginally related topic with no answer. So I would like to ask here. Is this a intended behavior or a bug? Is it possible to turn on “find_selected_text” feature for incremental find?
Thanks.

0 Likes

#2

Any comments? :smile:

0 Likes

#3

This is the intended behaviour

0 Likes

#4

Thanks jps. Do you know the reason behind this decision? Is it possible to change this behavior by a plug-in? I may be able to do something here if this is the case.

0 Likes

#5

It’s not customisable, but you can use the regular find panel instead

0 Likes

#6

You can write whatever specific functionality you want via a plug-in. I was just tinkering around with this so here are the commands fresh from my memory.

To get you started:

[code]import sublime, sublime_plugin

class ExampleCommand(sublime_plugin.TextCommand):
def run(self, edit):
[/code]

This will get you the current selection:

SearchTerm = self.view.substr(self.view.sel()[0])

This will let you find all matches for that text:

RegionsResult = self.view.find_all(SearchTerm, sublime.IGNORECASE)

This will clear the old selection:

self.view.sel().clear()

This will select the second occurance of SearchTerm in the document

self.view.sel().add(sublime.Region(RegionsResult[1].a, RegionsResult[1].b))

If you want your own input panel, you can use:

[code]self.view.window().show_input_panel(“Please enter custom incremental search text:”, “”, self.on_done, None, None)

def on_done(self, text):
RegionsResultFromInputPanel = self.view.find_all(text, sublime.IGNORECASE)

[/code]

These commands (taken from the menu) may also help you:

[quote] { “command”: “find_under”, “caption”: “Quick Find” },
{ “command”: “find_all_under”, “caption”: “Quick Find All” },
{ “command”: “find_under_expand”, “caption”: “Quick Add Next” },
{ “command”: “slurp_find_string”, “caption”: “Use Selection for Find” },
[/quote]

0 Likes

#7

Has there been any update to this ?

Coming windows/visual studio as I’m sure many users are I am completely used to the following sequence when coding:

  1. double click -> highlight word
  2. ctrl+f -> the highlighted text will be there in the search pane
  3. enter -> the search pane disappears and I’m back in the editor in the first match
  4. F3 -> move to next match

Is this common behavior really impossible in sublime ?

0 Likes

#8

The preferred way to do this on Windows is to press Ctrl+F3 instead: it’ll move to the next occurrence of the selected text.

0 Likes