Visual Studio identical token highlighting - visual-studio

I coded a Mancala game in Java for a college class this past spring, and I used the Eclipse IDE to write it. One of the great (and fairly simple) visual aids in Eclipse is if you select a particular token, say a declared variable, then the IDE will automatically highlight all other references to that token on your screen. Notepad++, my preferred Notepad replacement, also does this.
Another neat and similar feature in Eclipse was the vertical "error bar" to the right of your code (not sure what to call it). It display little red boxes for all of the syntax errors in your document, yellow boxes for warnings like "variable declared but not used", and if you select a word, boxes appear in the bar for each occurrence of the word in the document.
A screenshot of these features in action:
After a half hour of searching, I've determined that Visual Studio cannot do this on its own, so my question is: does anyone know of any add-ins for 2005 or 2008 that can provide either one of the aforementioned features?
Being able to highlight the current line your cursor is on would be nice too. I believe the add-in ReSharper can do this, but I'd prefer to use a free add-in rather than purchase one.

There is a RockScroll alternative called MetalScroll which is essentially the same thing with a few tweaks and improvements.
Also there is a small and simple WordLight plug-in that only highlights the identical tokens.
Both are open source and support code folding which is nice.
Imho, the bar next to the scroll bar in Eclipse is a lot more elegant solution than the scroll bar replacement of RockScroll/MetalScroll. Unfortunately I couldn't find any VS plug-ins that do it the Eclipse way, so I just stick with WordLight.

Check following addins
Productivity Power Tools- Displays error in scrollbar and
Highlight selected word

In a different question on SO (link), someone mentioned the VS 2005 / VS 2008 add-in "RockScroll". It seems to provide the "error bar" feature I was inquiring about in my question above.
RockScroll
EDIT: RockScroll also does the identical token highlighting that I was looking for! Great!

Old question but... Visual Studio 2010 has this feature built-in, at last.

The highlight functionality is conveniently implemented in VisualAssist.
In my opinion, they are both must-have.
1) Highlight identifier under editing caret:
Options -> Advanced -> Refactoring -> Automatically highlight references to symbol under cursor
2) Highlight search result - in all windows. Works for RegExps!
Options -> Advanced -> Display -> Highlight find results

About RockScroll: It doesn't highlight the identifiers. It only highlights the same string in the source code! If there are similar identifier declared : ex. _test and test, and test is highlighted it will highlight the string "test" in variable _test too! And it will also highlight the same string in a method called "sometesting()". So it isn't exactly like eclipse and doesn't work for me.

The automatic highlight is implemented in Visual Assist as the refactoring command "Find References". It highlights all occurences of a given variable or method, but that's not automatic (binded to a keyboard shortcut on my computer).
Here is an exmaple:

DevExpress CodeRush does this when you press TAB when the cursor is in an identifier, you can then tab through all the highlighted instances. There's also a DXCore plugin (the foundation upon which CodeRush/Refactor Pro are built) that does current-line highlighting.

In VS 2017, this can be solved by installing the Match Margin plugin.
It appears to be part of the Productivity Power Tools (which might be worth looking at for other features), but surprisingly, installing PPT didn't solve the problem for me, I had to install Match Margin separately.

The "error bar" functionality is provided in JetBrains ReSharper. I'm not sure if it does highlighting of references to the currently selected identifier.

For selected word(s) highlight function only, there is also StickyHighlight.
StickyHighlight supports Visual Studio 2010 & 2012.

Related

Better color coding for visual studio (2013)

I'm learning both Java and C# right now. I started with Java first, back in august. The class I'm using uses BlueJ as a compiler. BlueJ has this cool color coding, where it's not just key words or such, the background changes based on what exactly you're typing in.
(Because I'm terrible at explaining things, it looks like this: http://imgur.com/HvhJUgY)
It's made it so easy on my eyes. Now that I've started coding in C#, my eyes can't seem to adjust back to not having the colors. I find myself getting lost in where an if statement begins and ends, and end up having to put ridiculous amounts of space and comments between code to help me follow it better. Does Visual studio have any options to do this, or do I just have to suck it up and learn to adjust?
The colour coding is in the Fonts and Colors options. To get there select Tools/Options. In the dialog, select Environment/Fonts and Colors. For the code, you can set the options in the text editor but you can do it for all the other windows in visual studio too.
Solution:
You can download an extension. In Visual studio code, click on the button that has four squares on the right hand side of the VS code's window. Then, in the search bar, search for "Bracket Pair Colorizer 2." This extension should aid your vision when looking at code. Here's an example
picture. Also, this extension is customizable, letting you add any color you'd like to resemble different types of lines of code.
Settings
To customize your extension, under the extension name you will find a settings dial, similar in shape to the windows settings logo. Click on that, and then click on "Extension settings". From there, you have access to many useful settings.
If this solution has solved or helped you, please mark it as an answer and upvote it. Thanks!

Cleanup spacing - C++ / Visual Studio 2010

Is there a built-in feature or available add-on for Visual Studio 2010 that will clean up spacing in C++ code so that annoying blocks like this:
RandomVar=RandomList.RandomMethod();
will become
RandomVar = RandomList.RandomMethod();
(Same goes for spacing in loops, etc.)
...or do I need to do this myself with find/replace and regex?
I think You are looking for Edit->Advanced->Format document. This will re-format your current document according to settings in Tools->Options->Text Editor->c/c++->Formatting.
It's keyboard shortcut Ctrl+E+D in my case.
Although originally for C code formatting lint has been modified to cover C++ and ported to many platforms.
Some lint variants only report inconsistent layout, others can fix it for you. some are free others paid for versions.
This would be an outside the IDE fix as this is a sperate tool (at least traditionally it is!)
This wikipeadia article lists a few possible sources for lint tools
(this was a footer in my orginal question, but as that posed two solutions I extracted it here so you can accept a specifc answer should you find one apropriate)
This is not a proper "Solution" but a possible work-around without the need for finding external tools
In the "Tools" menu pick "Options..."
In this dialog navigate to
"Text Editor -> C/C++ -> Formatting"
Set the layout options as you
would like your code to look.
Click OK.
Now in a unit with "bad"
formatting from the menu select "Edit->Advanced->Format document" and the IDE wil reformat the
document to match your settings.
For C#, VB etc the "Formating" option has several sub nodes that provide a fine grain of control for the sort of spacing options you ask for. The list for C/C++ is flat and very limited by comparison. I suspect there is not enough flexability for the layout you want.
So you probably cannot get the formatting you want directly. How about...
Set the spacing rules you want for C++ in the C# settings
Temporarily adding a C# project to your solution
adding a class to that
emptying it.
paste the C++ in (causing a reformat)
copy back to the original file
rinse and repeat
remove the temporary C# project
I have to say this is not pretty, but given the syntactical similarities between C++ and C# its probably a close match.
The auto-formatting settings for C++ in Eclipse are more extensive than in Visual Studio, so I ended up using that instead.

ViM-like search highlight in Visual Studio possible?

ViM has this option hlsearch where a searched string is displayed in highlight mode at all places in the file it is found. Is there a way to do the same in Visual Studio?
That is, if I search for "foobar", then all the foobar in the file are shown highlighted and this display remains until my next search. I find this very useful to see the places in a function where a certain variable is used (without having to manually search for the next appearance of that string).
I am aware of the Visual Studio Task List which can be used to look up strings like TODO. I hope the reader realizes that this is not a good fit for my problem which is more general text search and highlight.
If you like vim and are using Visual Studio you may want to check out Viemu.
The hlsearch Feature is of course included.
Example Picture:
Viemu hlsearch http://dklein.taunus.de/viemuhlsearch.png
With best regards.
Visual Assist X does this, along with something akin to light-symbol-mode. Among other things, of course.
Visual Studio 2010 now supports Reference Highlighting. Click on or move the cursor to any symbol such as names of variables, classes, methods, properties, etc. and it will highlight all other references in the file. It also allows you to navigate between the references using:
ctrl+shift+down arrow or ctrl+shift+up arrow
I use the RockScroll add-in. It has multiple features, one of them is that if you double click on a word it will be highlighted everywhere in the file. This is very similar to what you describe. It is free (as in beer).
If you happen to really like Vim, you might want to look into ViEmu for Visual Studio . I'm just a really happy user of it :)

Notepad++ like search highlighting in VisualStudio

Notepad++ has a neat feature that combines search and highlighting. When you select a word, it is highlighted wherever else it shows up on the page, so it is an implicit search, which I find very very useful.
Is there a way to get that into VS?
I would also be interested in having these highlightings stick so that I can highlight more than one keyword (using different bgcolor of course), and even have all these keywords get highlighted automatically on the newer pages I open after making them stick. Now that would be really cool!
Check out this question and the related answers:
How to highlight occurrences of a search term in text in Visual Studio?
Visual Studio 2010 will introduce a feature called "Highlight References" for symbols in C# and Visual Basic and it will behave as you describe. The "sticky" highlight however is not supported yet (in 2010).
The same feature is also available in Eclipse. Very useful.
Sara Ford has a post on her blog about making a custom editor. Might be a good starting point for investigating writing your own addin or editor for achieving your goal.
http://blogs.msdn.com/saraford/archive/2006/08/09/693548.aspx

Plugin for Visual Studio to Mimic Eclipse's "Open Type" or "Open Resource" Keyboard Access

If you've ever used Eclipse, you've probably noticed the great keyboard shortcuts that let you hit a shortcut key combination, then just type the first few characters of a function, class, filename, etc. It's even smart enough to put open files first in the list.
I'm looking for a similar functionality for Visual Studio 2008. I know there's a findfiles plugin on codeproject, but that one is buggy and a little weird, and doesn't give me access to functions or classes.
Vs11 (maybe 2010 had it too) has the Navigate To... functionality which (on my machine) has the Ctrl+, shortcut.
By the way it understands capitals as camelcase-shortucts (eclipse does so too). For instance type HH to get HtmlHelper.
This isn't exactly the same as Eclipse from your description, but Visual Studio has some similar features out of the box (I've never used Visual Assist X, but it does sound interesting).
The Find ComboBox in the toolbar ends up being a sort of "Visual Studio command line". You can press Ctrl+/ (by default) to set focus there, and Visual Studio will insert an ">" at the beginning of the text (indicating that you want to enter a command instead of search). It even auto-completes as you type, helping you to find commands.
Anyway, to open a file from there, type "open <filename>". It will display any matching files in the drop down as you type (it pulls the list of files from the currently open solution).
To quickly navigate to a function, in the code editor press Ctrl+I to start an incremental search. Then just start typing until you find what you are looking for. Press Escape to cancel the search, or F3 to search again using the same query. As you are typing in the search query, the status bar in the lower left corner will contain what Visual Studio is searching for. Granted, this won't search across multiple files (I've never used Eclipse much, but that sounds like what it does from your description), but hopefully it will help you at least a little bit.
If anyone stumbles upon this thread:
There's a free plugin (created by me) for Visual Studio 2008 that mimics the Eclipse Ctrl+Shift+R Open Resource dialog (note, not the Open Type dialog). It works with any language and/or project type.
You can find it at Visual Studio Gallery.
Some of the neat features are available in Visual Assist X, though not all of them. I've asked on their forums, but they haven't appeared as yet. VAX gets updated regularly on a rough 4 week period for bug fixes and a new feature every couple of months.
If you are looking for an add-in like this to quickly navigate to source files in your project:
try the Visual Studio 2005/2008 add-in SonicFileFinder.
Resharper does this with the Ctrl-N keyword. Unfortunately it doesn't come for free.
Visual Studio doesn't have anything like this feature beyond Find.
Found this thread while searching for Eclipse's Ctrl+Shift+R, and after seeing the Visual Studio Gallery, found the DPack Tools (they are free, and no, I'm not endorsed in any way by them).
But it's exactly what I was searching:
- Alt+U -> File Browser (a la Eclipse Ctrl+Shift+R)
- Alt+M -> Code Browser (Method list in the actual class)
It has more features, but I'm happy with these ones.
I have been using biterScripting along with Visual Studio to do more flexible searching and manipulation.
It can search the entire workspace.
It can search within any project - EVEN IF THAT PROJECT IS NOT LOADED OR EVEN PART OF A WORKSPACE.
It can find things using regular expressions.
AND, ABOVE ALL, it can make bulk changes. For example, want to change the name of a class from CCustomer to CUser, I can do it in just a few command lines - Actually, I have written scripts for things like this I do often. I DON'T HAVE TO CLICK ON EACH INSTANCE AND MANUALLY DO THE CHANGE.
And, it is inexpensive ($0). I downloaded it from http://www.biterscripting.com .
I'm also comming from the Java Development side and was looking for the CTRL+T feature in the Visual Studio. The other answers refer to open file, but since in C# the class name and file name can be different this is not what i was looking for.
With the Class View or the Object Browser you can search for Objects and Classes
[View]->[Class View] or [View]->[Object]

Resources