Can I find multiple values and replace with a value in VS2010?
Find: "cat", "dog"
Replace with: "animal"
You can use regular epxressions in the "Quick Replace" window of Visual Studio:
Press Ctrl+H. The "Quick Replace" window opens
Expand Find Options.
Select "Use: Regular Expressions"
Put cat|dog in the "Find what" text box, and put animal in the "Replace with" text box
You can use | operator like cat|dog in search box.
More information at The Visual Studio IDE and Regular Expressions
Related
When I do a ctrl+shift+h to open the Find and Replace All dialog the cursor is in the Replace With textbox instead of in the Find What textbox like it should be ala Visual Studio 2008.
This means I have to shift+tab to go to Find What - it's completely infuriating and makes no sense. I'd prefer that it's focused in Find What then I should tab into Replace With but I can't find setting for this.
The reason for that is so you can select the text you want to find in the IDE and then hit ctrl + shift + h. It will prepopulate the Find field with the text you selected and will take you directly to "Replace with" field so you can specify what you want to replace it with. I don't think there is any way you can change that behavior.
You can use ctrl+f and extend the dialog to use as replace. If pressed ctrl+f Focus is always in the correct(search) field.
HI
I understand that we can search specific word/Variable in VS2010 editor. For example, If I used a variable called (MyTest) and I want to count how many times I used this variable/word in the code of say (10000) lines.
If possible, how can we do it in the current form or count the word in all form the project?
Thanks!
Assuming you wont to search for "MyVariable" press Ctrl+H and the Find/Replace Dialog should open. Enter "MyVariable" into the "Find what" field and again into the "Replace with" field. Set the Scope to "Current Document" and press the "Replace all" button. A message will popup telling "xxx occurrence(s) replaced.", where xxx is the number you are looking for.
Press the "undo"-Button once, if you want to revert the document-state to unchanged.
Can you not highlight the variable and press Shift+F12? This will tell you all of the matches found.
If you want to find the text "MyTest", here is a hacky way to do it.
Use the find dialog (CTRL F) to search for the text. You can modify the scope. eg Document, project etc
Click Bookmark all
Then open the Bookmarks window (View-Bookmark window) to see a list of all the bookmarks. It doesn't show the total number but you could easily count them manually here.
Ctrl + Shift + F to pull up the Find in Files dialog
Enter your search variable name and scope (document, project, solution etc)
Find all
Scroll to the bottom of the resulting Find Results and you'll see Matching lines: xxx
I call up Find and Replace dialog with Ctrl+H. On F3 it finds the result but then I must hunt the Replace button using the mouse. And on every new find, it changes the screen position. Is there any way to use this dialog using only keyboard?
It will save me a few precious seconds multiplied by some very large number (I'm in the middle of heavy refactoring).
In visual studio 2015:
Ctrl+H opens the Replace dialog.
Ctrl+F opens the Find dialog.
Within that dialog:
Alt+N - Focus "Find" entry field
Alt+P - Focus "Replace with" entry field
Alt+C - Toggle Match Case
Alt+W - Toggle Whole Word
Alt+E - Toggle Regular Expressions
Alt+L - Open "Look In" dropdown list. Use Up/Down and Enter to select from this list:
Current Block
Selection
Current Document
All Open Documents
Current Project
Current Solution
Alt+R - Replace Next
Alt+A - Replace All
Esc - Dismiss dialog
For example, to replace "foo" with "bar" within the current selection:
Ctrl+H - Opens the Replace dialog, with focus on "Search Term".
Enter "foo"
Alt+P - Focus is now on "Replacement Term"
Enter "bar"
Alt+L, choose "Selection", press Enter.
Alt+W - Whole word only
Alt+R - Replace first term
Esc - Close replace dialog.
Sorry,
As microsoft there is no keyboard shortcut as Replace Next,
You can check this url
http://msdn.microsoft.com/en-us/library/da5kh0wa.aspx
You could simply copy your desired replacement text before starting to F3 through your source text, and hit Ctrl+V when you hit the next match as VS selects the match text for you.
It is a hack, but it works.
If you dock the find/replace window then it will not move with each new find.
You can then alternate with 1 finger on F3 to move to next find, while hovering the mouse over the non-moving replace button to replace what you need.
It is possible to deactivate Resharper default behavior of "Alt+R" which provides a quick access to Resharper menu in Visual Studio.
Just uncheck it in Resharpers options:
enter image description here
Is there a way to save a search information in Visual Studio. For example if I'm constantly searching for "This string", match case, match whole word, look in 'Current Project'. Can I store this somehow as a saved search?
This is easy to do with a macro. Start with Tools + Macros + Record. Do a search, setting all the options you want, click Stop Recording. View + Other Windows + Macro Explorer. Rename the "TemporaryMacro" to something more suitable. Tools + Customize + Keyboard and assign a keystroke to the macro.
You now have a single keystroke to execute the search.
I found that if you do the following in VS2012:
1) Copy and paste the file types list back into the "Look at these file types" search box
2) Click and unclick the "Use Regular Expressions" checkbox
3) Press "Find Next" before "Find All"
4) Close visual studio and reopen the solution
For the actual search string I think if you make sure your cursor is positioned on a blank line, it will also reuse the last search string, otherwise it will pick the string under the cursor.
Then (at least VS2012) will remember the last search options. You may or may not also need to click your heels and perform some voodoo magic that i was doing at the time on the side (that part is a secret, sorry)
How do I make all occurrences of a phrase (search term) in a file to be highlighted in the VS code editor?
I noticed that a nice side effect of the Rock-Scroll plugin is that when you double-click a keyword it highlights all occurrences in the file (and in the rock scroll preview) as well.
http://microsoftdev.blogspot.com/2008/05/rock-scroll-visual-studio-plugin.html
Hope that helps,
Alex
ReSharper can do this with the Highlight Usages feature: Highlight Usages In File
Course, you need ReSharper ;)
I have just done a quick google for this very feature.
Came up with these results
VS 2008
http://visualstudiogallery.msdn.microsoft.com/en-us/ad686131-47d4-4c13-ada2-5b1a9019fb6f
VS 2010
http://visualstudiogallery.msdn.microsoft.com/en-us/4b92b6ad-f563-4705-8f7b-7f85ba3cc6bb
You can use metalScroll extension - it is like rockscroll but it has rich and very useful functions. You can download this on:
http://code.google.com/p/metalscroll/downloads/list
go through with this before use:
http://code.google.com/p/metalscroll/
When you run a "find" you can click "bookmark all"
which will identify on the left which lines the search terms occur on, but you can't "highlight" the elements using visual studio, out of the box.
If you use the CTRL-i short cut, it'll do an inline incremental search.
Keep pressing CTRL-i to jump to & highlight each subsequent occurence in the file.
I'm not sure that you can highlight all occurences at once. It may be possible with a plugin like ReSharper but not that I'm aware of.
Microsoft has an (actually) useful VS plugin which solves this issue.
Power Tools: http://visualstudiogallery.msdn.microsoft.com/d0d33361-18e2-46c0-8ff2-4adea1e34fef/
Once installed (restart VS afterwards), either highlight a section of text an hit CTRL+F to iterate all occurrences, or highlight text and let VS mark all matches for you in syntax highlighting.
CTRL + F3
sends current word to find, regardless if it is selected or not
steps to the next occurrence
AND highlights all occurrences in editor
TIP: Use SHIFT+CTRL+F3 to "step backwards"
I copied and pasted the source code into Word 2007. This has highlight all option called 'Reading Highlight'. This keeps the highlighting on even when you search for another term.
I open the file in Notepad++ and VS.
Update:
I recently found this extentnion for VS that makes it behave like notepadd++! You just need to select a phrase and it will highlight all of them.
Highlight all occurrences of selected word