Visual Studio Current Code File Highlighter Macro
A special thanks to my friend Adam for discovering the following:
If you are ever working in large solutions or projects with a lot of partial classes then this tip is for you. This macro in in Visual Studio 2010 will highlight the current code file in the solution explorer that you are working in. This is helpful when you open files via short cuts / navigation, etc. without directly opening the file.
Setup
1. Open Visual Studio
2. Go to Tools – Macros – Macro Explorer (or Alt + F8)
3. Right Click on MyMacros and select New Module…
4. Name the module ExplorerHelper and click Add
5. Double Click on ExplorerHelper under MyMacros
6. A code file will open up. Copy and paste the following code into the module.
PublicSub LocateFileInSolutionExplorer() DTE.ExecuteCommand("View.TrackActivityinSolutionExplorer") DTE.ExecuteCommand("View.TrackActivityinSolutionExplorer") DTE.ExecuteCommand("View.SolutionExplorer") DTE.ExecuteCommand("View.ViewCode") End Sub
7. Save the file (Ctrl + S)
8. Go to Tools –> Options –> Environment –> Keyboard
9. Change the Mapping scheme to default
10. Under Show command containing: type macros – then select the macro we just created.
11. Place the cursor in the Press shortcut keys: field and choose the keys you wish to use to launch this macro while in the code file. In this example I am using Ctrl + Shift + Alt + F. Once the keys are pressed – click assign to set the short cut. Then Click ok.
Usage
1. Open a solution
2. Open a code file
3. Collapse the solution. You should see something like the following
4. Now press the short cut key combination with the cursor blinking in your code file and the solution explorer will expand and highlight your current code file.
If you encounter the following error “Vsaenv: Cannot find one or more components.” when trying to open your macro solution – here’s the fix:
http://download.microsoft.com/download/8/C/E/8CE18AE7-CAA8-4A4C-87CF-0C3DF772322D/VS2010RTM.htm
Check out section 2.1.7.