Sticky Scroll: Stay in the Right Context
When coding in a long file, it’s easy to lose track of the method or block you’re writing in. Or when scrolling through an unfamiliar codebase, it can become disorienting where you are in the code.
Sticky Scroll can help you stay in the right context by sticking helpful scopes, including namespaces, classes, methods, loop initialization statements, and conditionals. Multiple code formats are supported, including C#, C++, XAML, and JSON. With a single click on a line in the Sticky Scroll header, you can quickly navigate directly to that line of code. Learn more about it from the previous blogpost.
We first released Sticky Scroll in 17.5 Preview 2 and it’s now moving into the latest 17.6 release! Since our last update, we’ve added a new option to stick inner scopes so you can easily track the scopes that are closer to what you’re working on.
Let us know what you think of Sticky Scroll in Visual Studio on this feedback ticket.
New: Choose between outer or inner scopes
We’ve heard feedback about how sticking outer scopes isn’t helpful. Oftentimes, the namespace and class name match the file name. It can feel wasteful to give up two lines of vertical space for info that is often obvious. Instead, it’d be more useful if lines that are likely to be different are shown instead.
In Options, you can configure whether outer or inner scopes are prioritized with “When number of scopes exceeds the maximum”.
“Prefer outer scopes” is set by default, which shows the higher-level scopes that come from the top of the file. The new option “Prefer inner scopes” shows lower-level scopes by pushing out higher-level scopes as you scroll through deeply nested code.
“Prefer outer scopes” shows top-level scopes:
“Prefer inner scopes” shows lower-level scopes:
Try Sticky Scroll in Visual Studio 2022 17.6
Enable it in Tools > Options > Text Editor > General > Sticky Scroll by toggling the checkbox for “Group the current scopes within a scrollable region of the editor window.” But if you need to quickly turn it off, you can right-click on the Sticky Scroll area and click “Sticky Scroll”.
Please Share Your Feedback
Let us know what you think of Sticky Scroll in Visual Studio on this feedback ticket and report any issues you face so we can improve the experience.
Sticky Scroll requires Block Structure Guides to be enabled for some languages (e.g., C#). If Sticky Scroll is not working, try enabling the following options in Tools > Options > Text Editor > C# > Advanced.
|Show guides for declaration level constructs||Affects namespaces, classes, method initializations|
|Show guides for code level constructs||Affects conditionals, loops|
Very Helpful! I didn’t know this feature existed before.
It would be nice to enable this functionality by hotkey – for example, while holding alt.
this comment has been deleted.
Yes. I agree. Can we get a shortcut key to switch between outer and inner?
Thanks for the feedback about switching between outer and inner scopes! Would you share more about when you need to switch between these settings?
this comment has been deleted.
Please one question
Can one use visual studio to create an APP for android, windows and IOS. And how can i do that
This is cool, but there really ought to be a hotkey or toolbar button to toggle this.
Thanks for sharing this suggestion! We’ve been tracking the ask for an easy way to toggle Sticky Scroll on this Developer Community ticket: https://developercommunity.visualstudio.com/t/Toggle-Sticky-Scroll-with-keyboard-short/10297395. You can upvote and add more details there to help us understand why this would be helpful.
While main idea is right, implementation is clumsy (as usual). Obviously it’s quite inconvenient to jump to options “prefer outer/inner scope” as well as switching this feature ON at all. Even students understand this feature must be activated BY A KEY.
Thanks for the feedback about how it’s inconvenient it is to turn this on! Would you share more about why it would be helpful to activate these via the keyboard? Is this a feature that you would often need to turn on and off?
that’s great! I waited a long time for this feature, thanks a lot!