Macro to sync active item in Solution Navigator - visual-studio

I don't like the "Track Active Item in Solution Explorer" option in VS, since it seems to slow things down a lot, and can be a bit buggy.
Instead, I'm using the macro shown here (http://weblogs.asp.net/kdente/archive/2008/04/30/locating-the-active-item-in-solution-explorer.aspx) to manually sync the solution explorer using a shortcut key.
Now, I'm switching from using Solution Explorer to the new Solution Navigator that comes with the VS Productivity Pack, and I'm missing this functionality a lot.
Does anyone know if there's anything I can do to manually sync the Solution Navigator to the active item?

Do you need to do this, as the Solution Navigator has an "Open" tab that shows all open files?

Visual Studio 2012 has this built-in using the SolutionExplorer.SyncWithActiveDocument command (default key binding is Ctrl+[, Ctrl+S

Related

Code Window does not highlight selected (usually .cs) file in "Solution Explorer"

My Visual Studio has done something really weird.
Usually, when you are in the "edit window" and are changing code, the file you are editing will highlight in "Solution Explorer".
Also, if all projects are "collapsed" in "Solution Explorer", and then there is a file already open (as in, you can see its "tab"), when you click the tab of that file (to be able to edit it), the Solution-Explorer will un-collaspse that project and highlight the file you are editing.
My "Solution-Explorer-Highlight-The-Current-File" function has stopped working.
I can move from tab to tab to tab, and Solution-Explorer doesn't react at all.
I've googled and binged, and I either get 5 billions hits ... or none. The key phrases are too ambiguous I think.
Anybody ever seen this one?
I have VS2010 on the same machine, and it works just fine.
I have one Add-In installed, but it is installed in both VS2010 and VS2012. Thus I don't think it's the culprit.
Smaller hammer.
From the menu: Tools -> Options
From the tree: Projects and Solutions -> General
On the form check: Track Active Item in Solution Explorer
Well.
From here:
How do I truly reset every setting in Visual Studio 2012?
I found this "Big Hammer" command line switch.
/ResetUserData
I used it.
And now it works.
I hate to answer something myself, but just in case somebody hits this in the future.

Backspace doesn't work in Visual Studio

I keep getting a very annoying problem in Visual Studio. When I try to delete some text by pressing backspace it doesn't work. Why is this? What is going on? Sometimes I have to close and open Visual Studio to make this problem go away but I just tried that right now and it didn't work. Backspace works in Notepad in case you are wondering.
In Visual Studio go to:
Tools
Options
Environment
Keyboard
Find "Edit.DeleteBackwards" command.
In "Use new shortcut in:" dropdown select "Text Editor".
In "Press shortcut keys:" click backspace so it would show "Bkspce"
Click "OK".
Backspace should start working for you again.
This seems to happen to me when I open a solution and there are files already open. I used to close the files, then close and re-open the solution to fix it, but now I just hit Alt + Enter.
Here is the blog where I found this trick.
I solved this issue resetting keyboard mapping scheme.
Tools -> Options -> Environment -> Keyboard -> Reset.
A quick fix for me is to simply open any menu from the menu bar. Once the menu is closed the non-character keys start to work again.
Except for the above methods.
You should also check the shortcut key settings:
File -> Preferences -> Keyboard Shortcuts -> 'Then check the item: deleteLeft'.
I get this from time to time in VS2010 as well and simply just using the mouse to change tabs/files seems to always fix it now. Nothing more.
This method is working at 100%.
Go to "File-> Preferences -> Keyboard Shortcuts" and search for deleteLeft and add keybinding "Backspace".
Odd that this is still an issue even in VS 2019. Both the backspace and delete keys didn't work. Quick fix, I just ran the project and it seemed to give it the kick it needed.
All I did was exit visual studio and restart it.None of the above options worked for me.
In my case the problem was the "When" Condition in "File-> Preferences -> Keyboard Shortcuts".
I removed "textInputFocus && !editorReadonly" and it works now as expected.
I'm looking forward to the side effects ;).
Try resetting your Visual Studio Settings
Go to :
All Program > Visual Studio 20xx > Visual Studio Tools
Run Developer Command Prompt for VS20xx as Administrator and this command:
devenv.exe /resetsettings
A quick work-around for me is locking the pc (Windows+L) and logging in again.
You can reset keyboard mapping scheme like this
Options => Environment => Keyboard then select (Default) in the comboBox and click Reset button and then Ok button to confirm
Visual studio 2019 : Keyboard mapping sheme
Tested in Visual Studio 2019
This problem happened for me when I used a different version of resharper at home and then took that project to my employment. Backspace works for me now after I deleted the bin and obj and resharper directories.
I have this problem after I install Vim, uninstall Vim Backspace works fine.
When this issue has happened to me, I've found that hitting delete or backspace is unresponsive only within a portion of my code. This portion happened to be some code that I've pasted in from the internet somewhere.
To fix this issue, I cut out the recently pasted problematic code and then pasted it into a text editor like Notepad++. Then copying and pasting that same code out of the text editor and back into Visual Studio fixed the problem.
Using Visual Studio Community 2019 (16.4.3)
I just searched this issue because I could click in my document, type, et cetera, but I could not use backspace, delete, ctrl+z, or the arrow keys.
Opening the "File" menu, I noticed the Save option referred to a different file. I checked that file and found that all of the keys that seemed not to work were actually editing that other file.
Switching between the file in half-focus and the file I intended to edit worked and, luckily, undo was able to fix the file I unknowingly butchered.
If you wound up here, check your "File" menu to make sure the correct file is referenced, since the fix is quick and easy to try.
Just had this exact issue (along with 'Enter', 'Ctrl+X', 'Ctrl+C', 'Ctrl+V', 'Ctrl+Z' keyboard mappings seemingly doing nothing) in the latest VS preview version below:
Microsoft Visual Studio Professional 2022 (64-bit) - Preview
Version 17.2.0 Preview 6.0
The fix for me was to move to another tab (I had multiple open) use the backspace key which worked fine, then move back to the original tab with which it wasn't working, save the file (as it had outstanding changes) and then I found backspace and all other shortcuts then worked!
I can only think that VS got in a locked (to keyboard mappings) state for that particular tab.
A few notes on this:
I knew it wasn't a keyboard issue as I was able to use those
keys/mappings fine in other apps.
I found closing and reopening VS didn't work.
Also resetting the keyboard mappings (through Options menu as others have described) didn't work.
I had multiple tabs open.
Resharper was disabled.
I just had this happen in one instance of Visual Studio 2022, caused by the debug settings editor window being open in another instance of Visual Studio 2022 in the background where I couldn't see it.
Closing that window resolved it.
I've had this issue for a long time. I'm not sure what causes it, but Alt + Enter works.
The extensions that I'm running include AnkhSVN, MySQL Tools, and Productivity Power Tools.

ReSharper 5.1 can't navigate to a type from anywhere

I'm running Visual Studio 2010 (10.0.40219.1 SP1Rel) with ReSharper 5.1 (5.1.3000.12). Recently, it seems as though ReSharper has completely lost the ability to navigate to a type.
Here are some actions I can take in the UI that now do nothing:
Right-click on type name in code
editor and select "Go To
Declaration"
Right-click on type name in code
editor and select "Go To
Implementation"
R# "Go to type" (Ctrl-T)
In the R# "Find Results" window, double-clicking a type
Here are some actions that still work:
Double-clicking an item in Solution Explorer
Opening a file from VS Command Window
I've completely uninstalled Visual Studio, then reinstalled it with SP1, and ReSharper 5.1, and I still have the same problem.
I'm assuming there's some kind of configuration open that I've done that is disabling the ability to navigate to a type with ReSharper, I just can't figure out what it is.
Any advice would be much appreciated.
I just experienced this problem. None of the previous suggestions worked for me unfortunately, but I managed to resolve it:
Go to Resharper -> Options
Under Keyboard Shortcuts, temporarily switch to a different scheme than the one selected
Press 'Apply Scheme' button then press Save
hen repeat, but this time select the scheme you actually want and press 'Apply Scheme'
Hopefully that fixes it!
I am using VS 2010 SP1 (same as you)
Delete the Resharper temp files in the same location as your solution file. The folder name will be something like _ReSharper.SomeSolution
Failing that, try one of the R# nightly builds here altho it should work with your current config.

How to locate a file in Solution Explorer in Visual Studio 2010?

I have a huge solution with multiple projects. Sometime I need to navigate to a file in Solution Explorer. Using the VS 2010 'Navigate To' feature I can open any file by name in Visual Studio 2010 but I want to be able to select the file in Solution Explorer as well?
There's an option to track the active (open and viewed) item in the solution explorer. If the file is in view, the file in the solution explorer will be selected.
Tools->Options->Projects and Solutions->Track Active Item in Solution Explorer
VS2012 added a new command called SolutionExplorer.SyncWithActiveDocument. The default shortcut for c# is Ctrl+[,S
This command will navigate to the active file in the Solution Explorer.
Also, it seems that you need to have the "Track Active Item in Solution Explorer" option turned off.
With ReSharper installed Shift+Alt+L will find the current file in Solution Explorer in Visual Studio 2008+.
I found the track option to be a little annoying.
I prefer to use DPack. It contain "Locate In Solution Explorer" operation, plus many other features (some are less powerful in VS2010, like their browsers), and it's free.
Note that ReSharper also have the locate feature that works batter than DPack's (in some cases, DPack's locate won't work if the file is collapsed behind folders), but you don't want to buy ReSharper only for this feature.
Brian Schmitt has a great Locate File in Solution Explorer – Visual Studio Macro post for this. The macro is extremely simple and quick. Basically it toggles the setting
Tools->Options->Projects and Solutions->Track Active Item in Solution Explorer
so that the current file ends up selected in the Solution Explorer but, because it is not left on, you don't get irritated by Solution Explorer nodes being expanded for all the files you access.
Public Sub LocateFileInSolutionExplorer()
DTE.ExecuteCommand("View.TrackActivityinSolutionExplorer")
DTE.ExecuteCommand("View.TrackActivityinSolutionExplorer")
DTE.ExecuteCommand("View.SolutionExplorer")
End Sub
Bind a Keyboard ShortCut to this custom macro to effectively create what should be a built-in Visual Studio feature.
If you have ReSharper and want to add "Locate in Solution Explorer" to the tab's context menu:
Go to Tools -> Customize -> Commands -> Context Menu
Select "Other Context Menus | Easy MDI Document Window".
Click "Add Command".
Choose "Resharper" -> "ReSharper_LocateInSolutionOrAssemblyExplorer" (in VS2019, the category name was changed to "Extensions")
"OK" -> "Close"
Now, when right click on any tab and you'll see a new option: Locate in Solution Explorer.
UPDATE:
Following the comment from #jeremy-paskali, you can set a keyboard shortcut for this command:
Go to Tools -> Customize -> "Keyboard..."
Search for "ReSharper.ReSharper_LocateInSolutionOrAssemblyExplorer" in the "Show commands containing" field and select it.
Review the currently assigned shortcuts in the drop down below.
Make any changes, if needed.
"OK" -> "Close"
Visual Studio 2012 has a new shortcut Ctrl [, S. Yes you have to type Ctrl [ and then release and then immediately type S (or click the little sync icon at the top of Solution Explored). It will synchronize to the item.
Of course you can change the shortcut. I think I'll try Alt+L for locate.
If you want to change the shortcut, it's command name under Options\Environment\Keyboard is SolutionExplorer.SyncWithActiveDocument.
Usually this is more useful than always tracking, which in older versions always was a disaster because it would track 100 items in a row and then be jumping all over the place...
I know its little too late, but hope it helps someone else. The best option now is to install Microsoft Visual Studio add on called - Productivity Power Tools.
http://visualstudiogallery.msdn.microsoft.com/d0d33361-18e2-46c0-8ff2-4adea1e34fef
With this comes "Solution Navigator" (alternative to Solution Explorer, with a lot of benefits) - which then you can use to filter the files to only show "Open". You can even filter files to show "Edited" and "Unsaved".
In the event you want to only track the current file through a
keyboard shortcut - the activity is
"View.TrackActivityinSolutionExplorer" (assign keys here -> Tools -
Options - Environment - Keyboard)
Credit (James' comment)
This worked for me
There are several build-in ways you can accomplish this nowadays:
Configure VS to track the active item in Solution Explorer: This can be accomplished by selecting "Track active item in Solution
Explorer" at
Tools > Settings > Projects and Solutions > General
Use "Sync with active document": This can be accomplished in 2 ways.
Firing the SolutionExplorer.SyncWithActiveDocument command by using the default key combination CTRL+]+S
CTRL+)+S if you happen to be using an AZERTY keyboard like me.
By using the "Sync with active document" button on top of the Solution Explorer. The button looks like 2 apposing arrows on top of each other.
If you're version is older then VS2019 Version 16.10.2 then this button looks like this:
From VS2019 Version 16.10.2 onwards this button will look like this:
And yet again Microsoft has changed the button icon in more recent versions of VS 2022:
In Visual Studio 2010 you can turn on the "Track Active Item in Solution Explorer" option. This will mean whenever you switch between documents the new document gets selected in Solution Explorer. This can be irritating if your solution has lots of folders, because as you move around files in your solution all the folders will be left open.
Visual Studio 2012 introduced the new "Sync with Active Document" feature. Three is a button for it at the top of Solution Explorer, or you can use the shortcut Ctrl + [, S.
This is actually built in to visual studio without the need for ReSharper (which I love BTW).
http://blogs.msdn.com/b/zainnab/archive/2010/03/29/track-active-item-in-solution-explorer-vstipproj0011.aspx
If you want to select the file in the solution explorer on command and don't want to install anything then I would recommend this macro.
I've tested it, setting the shortcut to Alt+T, and I can confirm that it works with VS 2010.
Thanks to Dan Vanderboom for writing it.
For Visual Studio 2017 using a French AZERTY keyboard the command is the same as stated by Aaron Carlson but the keyboard shortcut is different.
The AZERTY keyboard shortcut to navigate to the active file for c# is Ctrl+),Ctrl+S
I checked the shortcut hadn't changed for QWERTY users in VS2017 on this page
http://visualstudioshortcuts.com/2017/
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”.
Thanks to Cory House

Auto select file in Solution Explorer from its open tab

Normally, many files in Visual Studio 2010 are opened in many tabs, while massively working on a project. Many times, I find myself right-clicking on a tab title and searching for Show/Select/Scroll-to this file in Solution Explorer, and I can't find it.
Is there a way to automatically select an opened file in Solution Explorer?
Another option is to bind 'View.TrackActivityInSolutionExplorer' to a keyboard short-cut, which is the same as 'Tools-->Options-->Projects and Solutions-->Track Active Item in Solution Explorer'
If you activate the short-cut twice the file is selected in the solution explorer, and the tracking is disabled again.
Visual Studio 2013+
There is now a feature built in to the VS2013 solution explorer called Sync with Active Document. The icon is two arrows in the solution explorer, and has the hotkey Ctrl + [, S to show the current document in the solution explorer. Does not enable the automatic setting mentioned above, and only happens once.
I don't know if you can do it on-demand, but you can enable the option "Track Active Item in Solution Explorer" (Tools->Options->Projects and Solutions->General) which will always select the active tab item in the solution explorer.
If you're using the ReSharper plugin, you can do that using the Shift + Alt + L shortcut or navigate via menu as shown.
This isn't exactly what you're looking for, but it would automatically select the "active" file in the Solution Explorer:
Tools-->Options-->Projects and Solutions-->Track Active Item in Solution Explorer.
simply Tools--> Options--> Projects and Solutions--> Track Active Item in Solution Explorer
The best option now is to install the Microsoft Visual Studio add on called Productivity Power Tools.
With this comes "Solution Navigator" (alternative to Solution Explorer, with a lot of benefits) - which then you can use to filter the files to only show "Open". You can even filter files to show "Edited" and "Unsaved".
It's in VS2012 - Specifically the 2-Arrow icon at the top of the solution explorer (Left/Right arrows, one above the other). This automatically jumps to the current file.
This icon is only visible if you've got Track Active Item in Solution Explorer disabled.
In Visual Studio 2012, the same can be done using the "Sync With Active Document" option in Solution Explorer
In VS 2019 select Tools > Options and then tick "Track Active Item in Solution Explorer"
The Tab Studio plugin adds "select in solution explorer" to the right click menu on tabs.
I've put in a feature request for this very feature. Although I know this isn't an answer in itself it is a step in the direction of being able to get this feature implemented. Any votes it it may help to get Microsoft's attention.
As far as I'm aware of though there is no way to do this other than possibly writing a macro or creating your own add-in/extension to Visual Studio.
There's a very nice extension to VS2010, which does exactly this: Solution Explorer Tools.
This extension adds a button which selects the current file in the solution explorer, as well as convenient buttons for collapsing and expanding projects.
That's the screenshot of the answer for your question.
In visual studio 2022
Similar to this answer https://stackoverflow.com/a/8473574/13275637
You need to tick Track Active Item in solution Explorer

Resources