intelliJ -> is there any way to scope your search to be within a function - search

Very often while coding, I need to search for keywords which are common and happen throughout a large file, but I am looking for an instance within a function.
The default search functionality often gives me all results starting from the top. Is there any way/workflow to search only within a specific method/function or block of code?

Update
Do Ctrl + F
Then Ctrl + Alt + E
Type the text to search
On MacOS, it's cmd instead of Ctrl
Original Post
You can do it like this (mentioned keymaps are for Linux):
Let's take as an example the following code, where we will be searching for the word "key" inside the method "clear". As you can see there are many occurrences of that word (in red, highlighted the ones we want in our results, and in blue other occurrences, which we do not want to appear in our search results)
1- Select the area you want to limit the search scope to.
2- Press Ctrl+Shift+F. It will pop up a search window with the selected text pre-filled in the search box.
3- Select the options "Scope" and, in the combo next to it, "Selection" (if they are not selected by default)
4- Type the word(s) you want to search (in this example, the key word).
5- The results shown will be limited to the selected area. Notice how there are only 9 matches in the upper right corner ("Match case" option is checked), despite in the same file there are many other occurrences of the same word.
However, I was neither able to find a key combination in order to do this as a single action nor assign a new one. Also, notice how the search includes the text in the method documentation.
Tested using IntelliJ IDEA 2018.1.4 (Ultimate Edition), Build #IU-181.5087.20 on Ubuntu 18.04

Looks like we're finally getting this feature in IDEA 2019.3:
https://blog.jetbrains.com/idea/2019/09/whats-new-in-intellij-idea-2019-3-eap-2/ (Ctrl-F for subtitle "Ability to search in a selected area when using the Find action")
It’s now possible to search only in a selected area using the Find action (cmd+F / Ctrl +F). Simply select the code piece you need in the editor and invoke the Find action and the IDE will perform the search only in the selected area.
Screenshot from the article (was a GIF originally)

There is a way to search inside a method, however, it doesn't seem to work for other scopes.
When searching in file as usual, click "Find all"
You'll get a list of results in the bottom panel. If you enable "Group by file structure" (I had it disabled by default), you can get a list of matches for a particular method.

On IntelliJ in Mac:
In a file select the specific block in which we want to find
something
Press CMD + F
Press CTRL + OPTION + G
Notice that the cursor has automatically landed in the find toolbar's text field
Type in what is intended to be found
Press enter to move the cursor
to the first occurrence.

Related

How can I bulk search and find data with slight differences in different rows?

There is something I want to do; but i don't know if it is possible.
I want to know if I can do what I want to do with EmEditor or something else.
You can find an example of what I want below.
Example Picture:
• The data on the left does not have the full name.
• The data on the right are those with the full name.
I present a small video to express what I want clearly.
Please watch the video first and then see the sample files where you can try how to do what I want.
Sample Video
Sample Files
The file on the right contains much more data than the file on the left.
That's why the first thing that comes to mind is; so sorting is useless.
For example, the data in the 1st row of the data on the left; corresponds to row 2 of the data on the right.
So no one has the same row.
That's why sorting doesn't work; and I need to search the left side data one by one inside the right side data and find the full name.
FOR INSTANCE:
On the left: 10-infographic-solutions-part-1
On the right: 10-infographic-solutions-part-1-D5DADA
Instead of searching all of them one by one, I want to automatically find the left-hand data among the right-hand data.
I thought this might be possible with EmEditor; but I don't know how.
If this is possible I would like to know how.
Also, there is one more thing I want to know.
I have something to add to the end of each line; but I can't put a bulk cursor at the end of all of them.
How can I do this with EmEditor?
I hope I was able to express clearly what I wanted.
If there is anything that confuses you, please let me know.
You can use Advanced Filter to find multiple strings combined with Logical Disjunction (OR). To do this:
Open Missing Data.txt with EmEditor, select all (Ctrl+A), and copy all the text to the Clipboard (Ctrl+C).
Open Full Data.txt, and click the Advanced Filter button on the Filter toolbar.
Click in the list box of the Advanced Filter dialog box, and press Ctrl+V to paste the Clipboard contents to the list box.
While all the items in the list box are selected, make sure the Match Case, (None), and Logical Disjunction (OR) options are selected, but no other options are selected.
Click the Filter button.
You didn't write what you want to do after searches, but if you want to remove all the matched lines from Full Data.txt:
Click the Abort button if you are already filtering. Click Bookmark button, and Close to dismiss the dialog box.
Right-click on the left edge of the editor (or select Edit menu - Bookmarks), and select Delete Bookmarked Lines.
As for selecting the end of each line, you can drag Mouse while pressing Alt to make a zero-width vertical selection at right (or press Alt+E, E to make a vertical selection, and press End). See Multiple Selection Editing for more information.

Find and replace within selection in sublime text 3?

I've read this thread indicating how to find and replace within selection in ST2. Despite reading this thread but still cannot figure out if it's possible to do a simple find and replace within selection in ST3?
Ensure the find and replace panel is closed.
Select the text in which you want to perform the find/replace - i.e. define your selection.
Open the Find/Replace panel - if desired, you can use a keybinding to run the show_panel command by going to preferences -> keybindings, then adding this line to the user keybindings: { "keys": ["ctrl+shift+s"], "command": "show_panel", "args": { "panel": "replace", "in_selection": true } } to ensure that the "in selection" mode is active and skip the next step. (see the forums for more available args.)
Turn on "in selection" mode if it is not already active by clicking on the button in the panel.
Enter your find/replace terms and perform your find/replace
If you want to change the selection you are searching within, you will need to close and re-open the panel.
If the region/selection you are searching within always contains multiple lines, you may want to consider setting the following preference for convenience:
// When auto_find_in_selection is enabled, the "Find in Selection" flag
// will be enabled automatically when multiple lines of text are selected
"auto_find_in_selection": true,
Select the word by pressing CMD+D it selects 1 from whole file and show transparent selection of all related word you can press more times CMD+D for selecting all word then edit it all words take places
You can (using ctrl-h, then toggling the 'in selection' option from the dialog), but it's a bad design IMO. Firstly, if you have an area of text highlighted when you request 'replace', it should assume "replace in selection" automatically. Secondly, as soon as you choose 'replace' it thoughtfully cancels the text selection for you. The whole process ends up involving cumbersome repetition, or an illogical sequence of steps. Visual Studio gets the UI design right; Sublime does not.
Searching and/or replacing within only a selected area in Sublime is indeed possible.
If you have text selected, once you open the Find or Replace panels, you can select the button for Find in Selection (which is turned off by default unless you have the auto_find_in_selection turned on and select multiple lines) to have the operation you carry out only apply to the selected area.
In this example I'm doing the following:
Pressing Alt+F3 to select all instances of the word to, showing how many of them there are
Select the first paragraph and then open the Find and Replace panel with Ctrl+H
Turn on the option to operate within the selection
Replace all instances of the word to with the word FROM
Show that the instances of to outside of the selection are still there untouched.
Select the line/word/code and Press Ctrl+d.
Matched piece of text will be selected and will have cursor after them.
You can edit them together.
Ctrl+h is the shortcut for 'Copy and Replace' in all versions of Sublime.

Quick find next finds all Sublime text 3

I'm using Sublime text 3, build 3126.
When I select a variable with quick add next it is selecting all instances of the word, regardless of variable or string.
Is this a bug, or my settings just off?
Srom my default settings:
// Highlights other occurrences of the currently selected text
"match_selection": true,
Edit based on comment:
Check to refactor: https://github.com/s-a/sublime-text-refactor
You can also do cmd + click (ctrl + click on windows) and select the variable manually, not ideal but may work on a moderate amount of code.
Original Answer:
That is how it works, it doesn't filter by type of data, simply by text content.
See below:
match_selection settings the same:
// Highlights other occurrences of the currently selected text
"match_selection": true,

Visual Studio 2012 - Keeping the search box open when switching between files

Not a fan of the "updated" search box in VS 2012. When I perform a search, I'd like to keep that search box visible as I'm clicking through my file tab well. Right now, it seems like the search box can only be visible for one file at a time.
For example, I'm have 2 files open. I search for the word "eyepatch" in the current file. I next want to perform this same search on the next file. But when click on the next file, the search box disappears and I have to do a ctrl + f and type "eyepatch" again.
Anyone know how to make this easier?
Hit F3 (Find Next). It keeps the search text from the previous search upon next invocation.
Select [All Open Documents] from the drop down menu at the bottom of the Search Box

Replace String in all files in Eclipse [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed last month.
Improve this question
How can I search and replace a String in all files of my current project?
Let's say I have the string "/sites/default/" now I want it to be "/public/sites/default/", but there are almost 1000 files.
Goto "Search"->"File" from menubar at the top left
Enter text, file pattern and projects
Click "Replace..." button at the bottom
Enter new text click ok
Voilà...
Depending on the file type you are focused on, Ctrl+H will open up different types of search screens.
A more consistent hotkey would be using the Alt method: Tap Alt, then A, then F.
Efficient Order of Operations:
Ctrl+C the text you want to do the replacing (if available)
Highlight the text you want to be replaced
Tap ALT, then A, then F. Brings you to File Search. The selection from (2) will auto-fill the search box
In the “File name patterns” input box, type in “.java” for replacing all Java files or type in "" to replace in all files
Click “Replace…”
Ctrl+V (Paste). Or type in the value you want to do the replacing
Enter
You can find more details in my blog post: http://blog.simplyadvanced.net/android-how-to-findreplace-in-multiple-files-using-eclipse/
Use Ctrl+H for opening Eclipse search dialog, select appropriate search tab and select "Replace..." to get you to the "Search and replace" dialog
Strange but it is a two step task:
Search what you want
In the search tab right click and select replace , or replace all:
A demo at:
http://www.avajava.com/tutorials/lessons/how-do-i-do-a-find-and-replace-in-multiple-files-in-eclipse.html
Tonny Madsen said it right, but sometimes this is too simplistic.
What if you want to be more selective in your replacements since not all replacements are correct for what you're trying to do?
Here's how to get more granularity to do the replacements only in certain folders, files, or instances:
First, do like he said:
Click Search --> File... OR press Ctrl + H and choose the "File Search" tab.
Enter text, file pattern and choose your Workspace or Working Set.
Then:
Click Search
When your results come up, make some folder, file, or instance selections by Ctrl + clicking on the ones you'd like to select. Ex: here's my selection. I've chosen 3 instances, 1 file, and 1 folder:
Now, right-click on your selection and go to --> Replace Selected.... Here's a screenshot of that:
Enter what you'd like to replace it "With". In my case you can see it says it is "Replacing 190 matches in 4 files". Now click OK.
Voilà!
References:
Here's the tutorial I came across that taught me this: http://www.avajava.com/tutorials/lessons/how-do-i-do-a-find-and-replace-in-multiple-files-in-eclipse.html?page=2
ctrl + H will show the option to replace in the bottom .
Once you click on replace it will show as below
There is an option in search => file and shortcut is Ctrl+H. Go for further refer follow link. This is work fine with Eclipse Neon
Is there a way to find/replace across an entire project in Eclipse?
If you want to replace two lines of code with one line, then this does not work. It works in notepad++. I end up open all files in notepad++ and replaced all.
Ctrl+F gives me Find/Replace dialog box.
Or you can,
First Alt+A
Next Alt+F
Then press on Replace button.
If non of them worked:
Goto -> Window -> Preferences -> General -> Keys and search for replace then you will see binding for Find and replace. In the bottom of that window, you can add your key to Binding text box. There you can add or edit any keys as shortcut.
I have tried the following option in Helios Version of Eclipse.
Simply press CTRL+F you will get the "Find/Replace" Window on your screen

Resources