Visual Studio doesn’t offer an easy way to locate the current file you’re editing in the Solution Explorer on demand. You can set the solution explorer to always stay in sync with this simple setting:
Tools > Options > Projects and Solutions > General. Check “Track active item in Solution Explorer”.
However, the constant jumping around in Solution Explorer is distracting and be a hindrance when you don’t want to lose your current location in the explorer. So getting this behavior on demand is the way to go.
Now third party add-ons like ReSharper offer a convenient context menu for locating the current file in the Solution Explorer on demand, but we can pull it off quickly in Visual Studio via a simple macro bound to a keyboard shortcut.
Step 1 – Open Macro Explorer
Press Alt+F8 to open Macro Explorer
Step 2 – Rename default module
Right click on Module1 and select “Rename”. Rename Module1 to “LocateCurrentFileInSolutionExplorer”.
Step 3 – Write Macro
Double click the “LocateCurrentFileInSolutionExplorer” you just created. This will open the editor. Paste the code below into the Public Module “LocateCurrentFileInSolutionExplorer” body:
Public Sub LocateFileInSolutionExplorer()
Be sure to hit Ctrl+S to save.
Step 4 – Bind Keyboard Shortcut
Navigate to Tools > Options > Environment > Keyboard. Under “Show commands containing”, type “Locate”. This will select the “LocateCurrentFileInSolutionExplorer” macro you just created in blue. Bind to Shift+Alt+F (or other combo as desired) by pressing this key combination in the “Press shortcut keys” input box and clicking “Assign”.
Step 5 – Enjoy!
Hit the keyboard shortcut and the file will be immediately highlighted in the Solution Explorer. You may now resume slinging code like a boss.