Sublime text find in selection - sublimetext

When I select multiple lines of text in text editor Sublime Text 3, and try to find (Ctrl+F) an existing string in it, it fails. In fact, any highlighting I do somehow makes the string unfindable. For example, if I highlight all text in my file, and Ctrl+F an existing string, it is unable to find any matches. Only when the string I want to find is not highlighted can the string be searched.
I have the 'in selection', 'highlight matches', and 'wrap' flags on when highlighting. My user preferences are as follows:
{
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
"font_size": 10,
"auto_find_in_selection": true,
"trim_trailing_white_space_on_save": true,
"ignored_packages":
[
"Vintage"
]
}
Any help will be appreciated. I have been trying to figure this out for an hour. Originally I had "auto_find_in_selection" set to false - I thought that was the culprit, but the problem persisted even after setting it to true.

go to settings-> user and add this line:
"find_selected_text": true
next time you select a text and press cmd+'f' it will be there as default search.

I had been fighting with this problem as well and for now (ST3 Build 3059) it still seems to be a bug. It seems like that the editor is not updating the selection for the search/replace bar while you have it open.
Here's a workaround:
1) Close the find/replace bar
2) Make your selection
3) Open search/replace bar and enter your search query
Hope this helps!

Related

Exclude folded code in Sublime Text search

Is there any way to exclude folded code from search. When I search for text and that text appears to be in folded part of the code Sublime always unfolds that code snippet and its annoying. I could not find any settings regarding it.
You can make use of Sublime Text's "Find In Selection" feature - select all the unfolded regions, then open the find panel and perform your search with "in selection" toggled on.
Here is a plugin to do this:
import sublime
import sublime_plugin
class FindInUnfoldedTextCommand(sublime_plugin.TextCommand):
def run(self, edit):
folded_regions = self.view.folded_regions()
self.view.sel().clear()
self.view.sel().add_all(folded_regions)
self.view.run_command('invert_selection')
self.view.window().run_command('show_panel', { "panel": "find", "reverse": False, "in_selection": True })
To set this up:
from the Tools menu -> Developer -> New Plugin...
select the template plugin code and replace it with the above
save it, in the folder ST recommends (Packages/User/) with a name like find_in_unfolded_text.py - the filename isn't important, just the extension is.
Open the ST console (View menu -> Show Console)
Type/paste view.run_command('find_in_unfolded_text') Enter
Enter your search string
Violia! The folded text is ignored.
As an alternative to steps 4 and 5, you can add this new command to the menu, to the command palette, or create a keybinding for it.

Sublime Text: disable refresh/replacement in 'Replace' function?

using the "Replace..." [Find menu] function a slide-in at the bottom appears with an option field/entry for "Find:" and below that one, one for "Replace:"
having completed a replace [eg "Find: abc", "Replace: xyz"] for instance by employing "Replace All" the very slide-in disappears
now for another, new, search, for instance within a document having selected a different, let's say word like "oha", that selection 'oha' is auto-copied over as new entry in "Find:" when using "Replace..." again. this is to say that now in "Find:" the entry does read "oha" tho didn't paste it manually in -- the "abc" entry fromthe previous search got replaced
however, the last entry in the "Replace:"-entry-field remains unchanged
it's the "Find:" entry that get's auto filled in w/out the option [as far as i could figure out]
and that exactly is my question about :
any option to modify Sublime's settings such that nothing gets changed/auto-copied/filled-in at "Find:" ?
pretty annoying behaviour, as i experience it, for instance when having to replace just a single character combi within similar text and each time the copy-selected text get's auto-copied/filled-in at "Find:" rather than leave it be till the usr opts to modify that entry from previous replace-calls
The Find and Find and Replace widgets automatically populate the Find box with either the current selection if there is one, or the previous value used in that box. This box is a dropdown, which contains the previous values used, so you can easily go back through your history in that window and not have to re-type a complicated regular expression, for example.
When the Find box opens pre-populated with a value, it is automatically selected, so to get rid of it all you have to do is hit Backspace or Delete. Alternatively, you can just begin typing your new search query, and it will erase the old one.
There is a setting in Sublime Text 4 that modifies this behavior:
// If true, the selected text will be copied into the find panel when it's
// shown.
// On Mac, this value is overridden in the platform specific settings.
"find_selected_text": true,
If you set "find_selected_text": false, in your user settings, you can disable this behavior.

Disable word-wrap by default in Sublime "Find in Files" results

Sublime's "Find in Files" (CTRL-SHIFT-F or CMD-SHIFT-F) search results always have word wrap on by default. This is really annoying whenever a file containing a single huge line of text gets caught in the results, since:
wrapping the huge line takes ages and slows Sublime (and perhaps the whole computer) to a crawl, and
it makes the results difficult to read, since the wrapped line may take up screens and screens of space
It's possible to disable word-wrap from the "View" menu, but this change doesn't persist after closing the "Find Results" tab.
Is there a way to turn off word wrap for all Find Results?
Yes, with the Find Results tab active (ensure the "Use Buffer" option is enabled in the Find in Files panel to get a tab instead of an output panel when you perform the search), you can navigate to the Preferences -> Syntax Specific menu item and enter:
"word_wrap": false,
and save it. This will ensure that word wrap is always disabled for Find Results.
(You can always turn "Use Buffer" off again afterwards, it's only necessary for the menu item to open the correct syntax specific settings file, which is Packages/User/Find Results.sublime-settings.)
In default, Sublime opens the files without word wrapping. If you want to enable it, just go to Preferences > Settings and add "word_wrap": true to the Preferences.sublime-settings file

How to select all instances of selected region in Sublime Text

Is there a shortcut key or single-step menu option to find and select all instances of a highlighted selection in Sublime Text?
On Mac OS you can use: CMD + CTRL + G
On Windows/Linux press Alt+F3.
On Windows/Linux press Alt+F3.
This worked for me on Ubuntu. I changed it in my "Key-Bindings:User" to something that I liked better though.
On Mac:
⌘+CTRL+g
However, you can reset any key any way you'd like using "Customize your Sublime Text 2 configuration for awesome coding." for Mac.
On Windows/Linux:
Alt+F3
If anyone has how-tos or articles on this, I'd be more than happy to update.
Note:
You should not edit the default settings, because they get reset on updates/upgrades. For customization, you should override any setting by using the user bindings.
On Mac:
Sublime Text 2 > Preferences > Key Bindings-Default
Sublime Text 3 > Preferences > Key Bindings
This opens a document that you can edit the keybindings for Sublime.
If you search "ctrl+super+g" you find this:
{ "keys": ["ctrl+super+g"], "command": "find_all_under" },
In the other posts, you have the shortcut keys, but if you want the menu option in every system, just go to Find > Quick Find All, as shown in the image attached.
Also, check the other answers for key binding to do it faster than menu clicking.
Even though there are multiple answers, there is an issue using this approach. It selects all the text that matches, not only the whole words like variables.
As per "Sublime Text: Select all instances of a variable and edit variable name" and the answer in "Sublime Text: Select all instances of a variable and edit variable name", we have to start with a empty selection. That is, start using the shortcut Alt+F3 which would help selecting only the whole words.

How can I find and replace inside a selection in Xcode?

In Xcode < 4, you could hold the "option" key, and the "Replace All" button would change to "Replace in Selection". As of Xcode 4, this does nothing. Anyone know if there's a new way to do it, or is it bug filing time?
This appears to be working again now, at least in Xcode 4.4.1.
When the find/replace bar appears at the top of the editor, holding down the option key on the keyboard causes "Replace in Selection" to appear in lieu of "Replace All."
I'm glad, because this was an ANNOYING omission.
Another workaround:
In Xcode, select the text, press copy
In a terminal session:
pbpaste|sed 's/SOURCETEXT/NEWTEXT/g'|pbcopy
Return to Xcode window, press paste
Since the original should still be selected, it will just be replaced. You could probably build a simple shell script to do this.
Doug
An few images to supplement the chosen answer:
And holding down Option:
See also
Find/Replace in Xcode using Regular Expressions
Seems like missing functionality. You should file a bug report.
I'm upset that they took out this functionality, as I used it constantly, but here's my workaround. Copy your selected text from Xcode4 to TextEdit or some other word processor, do the find and replace there, and then copy the results back into Xcode.
It's not sexy but it's worth it if you do a lot of these "find and replace on my selection", and you leave the word processor open in Spaces as you work.
They should add "my selection" as an alternative to "workspace" and "my scope".
There is another way only replace the matches you find, rather than just this one or all of them.
I suggest you save a copy first, just in case....
In Find and Replace, Show Find Options (you can do this by pressing the magnifying glass).
Press Preview.
Uncheck all the ones you don't want replacing.
Press Replace
Hope that helps, it did me.
Not ideal, but not too bad:
Do a find and replace in workspace (cmd-opt-shift-f) enter your desired find/replace
Enter your desired search term and hit return
Select the range of replacements from the list of matches on the left
Hit replace (not replace all)
To replace text in a selection using Xcode 9
Press Option-Command-F to bring up the find/replace box.
Enter the search and replace string. Changing the search string will lose any existing selection, so..
Make your selection (again). (If you don't do this, the selection will be the first search string found only)
Hold down the key and "Replace All" will change to "Replace Selection", then click it.
Once you understand that you make your selection AFTER you have entered the search string, then this is not that clumbersome and works fine.
I find alt-command-f easier for local find and replace (4.3) and then working around your selection.
EthenA.Wilson asked in a comment to the OP a couple of days ago:
"Is there a way to do this in Xcode 5?"
For the benefit of those who, like me, had been searching for it, here's how:
After you put your Find and Replace terms in the bars at the top left-hand side of the editor page, select the text you want to search in, then look at the top right-hand side (same bar). You'll see where it says "All", right next to "Replace." Now press the Option key. "All" will change to "All in Selection." Click it, and you're done. Could be a bit more intuitive, but the functionality is there in Xcode 5.
Naturally, good idea to take a snapshot before you click!
HTH!
Not sure which feature prior to Xcode 4 you're referring to, but the shortcut Command+Shift+E gives you "Use Selection for Replace". If you're talking about "Find and Replace in Workspace" (Command+Option+Shift+F), then what you need to do is run your find and then hold down "Shift" or "Command" on the selections shown and then hit "Replace".

Resources