Permanently highlight all occurrences of a specific keyword - visual-studio

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.

Related

What is the keyboard shortcut to type fast in Visual Studio?

I am not sure what is the best way to word my question correctly in single line. But basically I have seen quite a few video tutorials now where the coder types really fast using some sort of shortcut to fill in the automatic text(prolly intellisense stuff) It looks very similar to Linux command line tab where you only type half of your text and when you hit tab it either fills in the gap or show you the remaining options.
Hope that makes sense.
Thanks
Pressing Ctrl+Space completes the current variable/class you are typing.
Typing things like ctor and then pressing the Tab key twice tells Visual Studio to insert a constructor for you. (Also works with for for a for loop, cw for a Console.WriteLine();, etc.)
For a full list, please refer to the official reference from MSDN.
I believe its Ctrl-Space, which is pretty common among most IDE's

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/

Stop formatting portion of the code in Source Editor in Visual studio

In visual Studio aspx editor, i want to stop portion of the code to be formatted on format using ctrl - K ctrl - D .
Problem faced.
I am using two validator with text '*', both should be in same place i adjusted using css. But when format the code , this formatting introduce extra space.
If anybody knows the solution for this, please answer for it.
Expectation:
I am expecting a marker tag, to stop alignment.
For example,
<DontChange><asp:....>......</asp:....>
</DontChange>
When i give like this content between DontChange tag should not be aligned in Editor on every align.
This is an excellent question. Does highlighting the code block and selecting Edit->Advanced->Format Selection (or press Ctrl+K, Ctrl+F) work?
I don't think it's possible. Somehow VS would have to remove the extra tags when you build/deploy. I belive a simple <%-- --%> comment somehow should disable the formatting, but I haven't found anything yet :(
Perhaps an extension/plugin could do the trick?

Multiline Find & Replace in 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.

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