Multiline Find & Replace in Visual Studio - visual-studio

Can it be done? We're using VS2005, VS2008, and VS2010.
I don't mean regular expressions—which have their place—but plain old text find and replace. I know we can do it (at a pinch) with regular expressions using the \n tag, but we prefer not to get tangled up in regex escape characters, plus there's a readability issue.
If it can't be done, what plain and simple (free) alternative are people using? That doesn't involve knocking up our own macro.

I finally found it...
There isn't any need to download and load any external macro.
It’s working in Visual Studio 2008 with in-built macro at least. :)
Steps:
Select text you want to find.
Press Alt + F8 or open "Tools -> Macros -> Macro Explorer"
Double click Sample → Utilities → FindLine. (It will open the Find box with your selection loaded in the "Find" field. Don't worry about truncated text shown in the "Find" field. Trust me, the field has it all... The Microsoft way of showing it may be... :) )
Click on the "Quick Replace" button in the "Find And Replace" dialog box. Enter your replace with text.
And click any of three buttons as per your requirement...and it’s done. :)
Hurray... it’s working. It may not be a straightforward way to do it, but you know with Microsoft. Nothing is straightforward and easy.. :)

This works today in Visual Studio 2012:
fooPatternToStart.*(.*\n)+?.*barPatternToEnd
See how the (.*\n)+? part does the match across multiple lines, non-greedy.
fooPatternToStart is some regex pattern on your start line, while barPatternToEnd is your pattern to find on another line below, possibly many lines below...
Example found here.
Simple and effective :)
Note: before VS2012, the pattern that worked was: fooPatternToStart.(.\n)+#.*barPatternToEnd

You can search for multiline expressions by clicking on the "Use Regular Expressions" checkbox in the "Find and Replace" dialog. Line breaks are then indicated by \n.

I use this:
Visual Studio Gallery Multiline Search and Replace

It’s provided by Microsoft only. Please check Multiline Search and Replace.
It uses regular expression only. But for those who don't know regex, it is better to use it.

You could also open the files with UltraEdit which fully supports MultiLine replace.
You can use the trial version if you only intend to use it once.

Regarding the comment of Andrew Corkery:
If you like to specify a multi-line replacement string as well, edit the macro code and set the replacement text as shown below.
This will allow you to "fine-tune" your replacement with just the small modifications needed.
Sub FindLine()
Dim textSelection As TextSelection
textSelection = DTE.ActiveDocument.Selection
textSelection.CharLeft(True)
DTE.ExecuteCommand("Edit.Find")
DTE.Find.FindWhat = textSelection.Text
' Also preset replacement text with current selection
DTE.Find.ReplaceWith = textSelection.Text
End Sub

The latest version (as of this posting) of Notepad++ does multi-line find/replace. With no macro support in Visual Studio any more, this is relevant now.

Related

Permanently highlight all occurrences of a specific keyword

I'm editing a hugh Javascript file. For better orientation, it would be cool if I could change the style of all function keywords (not changing the style of all other keywords).
Can this be done in VS 2012 with Resharper?
Actually you can do this without ReSharper. Press ctrl+f, type "function", press enter and don't close find window. All occurences of word
"function" will be highlighted and you can continue your editing. When you close find windows, highlighting will be gone.
It's acutally not so hard to write a VS extension that does that or similar things. See templates etc. here: http://msdn.microsoft.com/en-us/library/dd885242.aspx
I'll mark this as the accepted answer as soon as I can.

How to change the highlight color for matched braces in VS2010

I need to change the highlight color for the matched braces in VS2010.
I have tried the following setting but it doesn't work at all.
Any suggestion is welcome.
Thank you
From Microsoft
...There are two Fonts and Colors options for brace matching: "Brace
matching (Highlight)" and "Brace matching (Rectangle)". Not all
languages use both settings. Each language implements its own brace
matching functionality, which can lead to inconsistencies in which
options are used in which language. For example, C#, HTML, CSS, and a
few others do not use the "Brace matching (Highlight)" option at all,
which is why it doesn't do anything when you change it in those file
types. However, "Brace matching (Rectangle)" should still work for C#,
HTML, and CSS, which it sounds like is consistent with your
experience. Some other languages will have the reverse behavior, i.e.
"Brace matching (Rectangle)" will do nothing but "Brace matching
(Highlight)" will work...
Not a good answer, but that's where VS2010 stands right now. Incidentally, when I changed
"Brace Matching (Rectangle)" Background color, it works for me in C++ and C#, if I have my cursor immediately left of an open brace or immediately right of a closing brace.
Good luck.
(tools) (options)
under (environment) (fonts and colors)
show settings for (text editor)
under (display options) there are two brace matching entires
(Brace Matching Highlight) is the one that you want.
Change it, maybe restart vs 2010 for good luck.
I use Visual Assist X for that task. After setting up visual assist for Visual Studio, you can change the bracer match and mismatch color under the display tab in the Visual Assist options menu.
Change Highlighted Reference in Item background dropdown
Watch it, if you use ReSharper, these settings will have no effect.
You first have to enable the Fonts and Colors in the newest ReSharper version.

alternative to Resharper "go to file" and "go to implementation" features

Does anybody know a light plug-in that do (same as Resharper) go to implementation and the quick search for a file where you just insert few characters and it shows the matches? I just want to get rid of Resharper cause it slows me down a lot!!
To answer the original question, as per this post by Andrew Arnott, you can use Ctrl+/ to move the cursor to the Find text box in the toolbar, then type ">of" and start typing file names. The matching files will appear as you type.
Using the ">" prefix causes the find text box to act as the command window would.
(Note that the Ctrl+/ short-cut may be overridden by ReSharper to comment a line of code, so this short-cut only works with ReSharper uninstalled.)
That's interesting. I use ReSharper and it uses about 400mb of RAM. I would consider that pretty low usage.
Maybe you can look into Productivity Power Tools (I don't use it).
http://visualstudiogallery.msdn.microsoft.com/d0d33361-18e2-46c0-8ff2-4adea1e34fef/

Visual Studio stack trace in notepad++

This is probably just a setting I'm not seeing, but when I get a stack trace out of Visual Studio's exception helper dialog, it has \r\n after each "line" in the call stack. When I copy this and paste it into Notepad++, it shows up as literally \r\n, visible in the document. Of course I'd like these to be interpreted as CR LF, so everything's on a different line.
Anyone know how to do this?
I know this question is old, but maybe someone will find the solution helpful.
Open find and replace, and
go to the replace tab
In the find box type \\r\\n
In the replace box type \r\n (both without quotes)
Make sure the Extended search mode is selected in the bottom left.
Finally, hit replace all.
.
It took me a while the first time to find the setting. It's View >> Show Symbol >> Show All Characters.
This sounds like a Notepad++ bug. I can paste into regular Notepad and UltraEdit without the side effects you describe.
Like Cerebrus says, you can workaround it on the Notepad++ side by using its search/replace facility.

How to highlight occurrences of a search term in text in Visual Studio?

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

Resources