Sublime Forum

Smart search / replace within selection lost on ST3

#1

Hey, guys.

Not sure if this is a bug or a feature, hence, this thread.

On ST2, when your selection included a line break and you hit Ctrl+F or Ctrl+H to either search of replace, the “within selection” option was turned on, automatically. This feature appears to have been lost, broken, or removed on ST3.

If it’s broken or lost, this is plead to the devs to fix it or add it - I use ST3 on a daily basis (I know I’m not supposed to be working with it, but it’s just too tempting), and other than goto-anything, this is probably the feature I used the most, and I sorely miss it.

If it has been removed, this is a plead to the product owners to splash some cool water on their faces and regain control of their senses. I have nothing but the uttermost admiration for the ST team in general, but, guys, I’m dead serious - this killer feature is a must have.

Thanks.

0 Likes

#2

+1 - when doing a replace on a block of text in a document - I keep having to reclick the “In selection” icon on the replace bar. This greatly slows my task because it makes me have to reach for the mouse for what would otherwise have had been a keyboard-only operation.

If I wanted to do a replace on the whole document - then I wouldn’t have selected anything first (or would have cleared my selection). if I have something selected - then I would like the replace bar to assume to replace “in selection”.

0 Likes

#3

+1 I hit this several times today.

0 Likes

#4

This is very important to me as well. I think this is a “feature,” since the ST3 beta announcement lists: “Find: Find in Selection will no longer be automatically selected”.

0 Likes

#5

Thanks, foozlex - hadn’t seen that.

Amazing.

Is there any way to put this to a vote? I feel like it’s just plain wrong. I doubt the kind of power users Sublime attracts would be baffled by the smart activation of “within selection”. Getting complains about how “confusing” it is is the only reason I can imagine for them to have cut it.

0 Likes

#6

[quote=“skqr”]Thanks, foozlex - hadn’t seen that.

Amazing.

Is there any way to put this to a vote? I feel like it’s just plain wrong. I doubt the kind of power users Sublime attracts would be baffled by the smart activation of “within selection”. Getting complains about how “confusing” it is is the only reason I can imagine for them to have cut it.[/quote]

I’ve posted about this in the technical support forum before, and got no reply. There was also a thread by jdao that was about this same issue, which also sunk into oblivion. I’d at least like a setting that lets you toggle this behavior.

0 Likes

#7

I generally avoid to post “me too” replies, but, please, bring back Find in Selection!

0 Likes

#8

+1 on this being very frustrating and also feeling like a bug.

Can you please add a “smart” flag setting that turns this on if the search/replace is invoked after a selection is made? So, invoking a search/replace without a selection keeps this off and you end up searching/replacing globally, but, starting *with *a selection constrains the action only inside the selection.

0 Likes

#9

Is there a way I can bind a hotkey to the “In selection” button in the replace bar so that I don’t have to reach for my mouse?

Update, figured it out:

{ "keys": "alt+s"], "command": "toggle_in_selection", "context": {"key": "panel", "operand": "replace"}, {"key": "panel_has_focus"}] },

Still, when I am doing a replace - it is 80% of the time “In selection” and 20% in the the whole document. I would prefer that it is always “in selection” whenever I invoke the replace bar with something selected.

0 Likes

#10

Thanks a lot robertcollier4, I’ve added your keymap and it makes things much easier.

I tried combining the showing of the panel and the toggling of the selection in a single macro. Have a look at the macro code below. It didn’t work, the console complains that both commands are unknown.

Any idea how the two could be combined? Also, can you set the selection mode instead of toggling it? I’d like to be able to invoke the Replace panel with the setting set to on, regardless of its previous state.

  {
        "command": "show_panel", 
        "args": {"panel": "replace", "reverse": false}
    },
    {
        "command": "toggle_in_selection", 
        "context": {"key": "panel", "operand": "replace"}, {"key": "panel_has_focus"}]
} ]
0 Likes

#11
import sublime, sublime_plugin

class ReplaceInSelectionCommand(sublime_plugin.WindowCommand):
	def run(self):
		self.window.run_command("show_panel", {"panel": "replace"})
		self.window.run_command("toggle_in_selection")

In key-bindings:

{ "keys": "ctrl+r"], "command": "replace_in_selection"},

I am wondering this as well. So far - I have only found “toggle_in_selection” working but don’t know if I can pass it a “true” or “false” arg to deterministically set a hotkey to turn it explicitly on or off. Sublime commands not being officially documented is a huge problem. I figured out the “toggle_in_selection” command via guessing what the author might have called it and trying a couple of possible command names. Guessing command names is not how an API is supposed to be use.

0 Likes

#12

Sorry to be a pain, but could I minus-one this? Or at least ask that it be setting in your user preferences?

I quite often want to search for a line or multiple lines of text, and it would be quite annoying if I had to repeatedly turn “search in selection” back off after each selection.

0 Likes

#13

Much obliged!

0 Likes

#14

Ah, thank god for the flag to turn this back on…but why did they ever decide to make it not the default behavior??

0 Likes

#15

This functionality appears to be broken in the latest build (3126).

0 Likes

#16

I confirm that this feature is broken in 3126 and worse: I use regex to do a search and replace and if I click on the “selection only” button, it finds nothing. If I don’t try with a section and click on “find” button then “replace” button, my regex works and it replace things like it should.

My regex is (search for end of sentence and add a newline - I want each sentence on one line)
find what: (.+)\ +
replace with: $1\n

0 Likes

#17

I also had problems with auto_find_in_selection.

You’re probably better off with auto turned off, and an hotkey as shown here

0 Likes