When working in code with long classes and methods that stretch beyond the vertical size of your screen, it can be difficult to keep track of which scope you’re working in. You may be editing a long method or exploring an unfamiliar codebase.
In Visual Studio 2022 17.5 Preview 2, we introduced Sticky Scroll to help you be more productive and save time when going through your codebase. Sticky Scroll provides immediate context to the code in which you’re working by keeping the relevant headers in your view. To start using Sticky Scroll today, update to the latest version of Visual Studio Preview and enable it in Tools > Options > Text Editor > General > Sticky Scroll by toggling the checkbox for “Show the nested current scopes during the scroll at the top of the editor”.
Stay Oriented in Your Code as You Scroll
As you scroll through your code, namespaces, classes, and methods will stick to the top of the editor! Sticky Scroll supports multiple code formats, including C#, C++, XAML, and JSON.
Single Click Navigation
In addition to sticking to the top of the editor, the headers also take you straight to that line of code. Clicking on one of these lines will quickly navigate you to the top of that indentation level.
Try It Out in Visual Studio 2022 17.5 Preview 2
Enable it in Tools > Options > Text Editor > General > Sticky Scroll by toggling the checkbox for “Show the nested current scopes during the scroll at the top of the editor”. Â You can also set the maximum number of sticky lines with the “Define the maximum number of sticky lines to show” option.
Please Share Your Feedback
We hope this feature will help you be more productive with your coding. As we continue to work on this feature, we appreciate 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.
Preview of how it works here https://www.youtube.com/watch?v=gwA06jLainw&t=27s
Thanks!
Much Needed feature!
But does it work for others than C#?
Yes, Sticky Scrolling works in any language that already supports Structure Guides (vertical gray dashed lines).
Fascinating – I planned to implement functionality just like this for my hex editor when viewing nested bookmarks and file trees. So it appears I’m not the first to think of it! C++ is my primary language, which I’ll try this for, but I anticipate this will be much more useful for asymmetrically nested languages like Python (which lack any visible closure, making it more challenging to find the corresponding opening statement).
I was wondering why have you not made any Record Structures Inherit Structures. Like this for Example? You Have A Short Structure Called Weapons
Like this fore example: private Weapons = Record
private int32 ...
The feature is cool, but I had to turn it off because it breaks VS when you’re working with javascript code.
Thank you for letting us know about this problem! To help us figure this out, would you be able to follow the instructions on this page here to share crash info from your logs?
thank info , i like your artikel
I work a lot with F# and this feature just gets it wrong which lines to make sticky. Then the second problem is that there is only a global switch for it so you can’t have it on for C# but off for languages it can’t cope with!
To further rub salt into the wound. The VS Code equivalent feature works well with F#.
David, thanks for reporting this, but can you please file a feedback ticket with some minimal F# repro code via Help/Send Feedback/Report a Problem?
Assuming that the issue with F# will be fixed, would you still prefer to enable Sticky Scrolling only in some languages?
I did file it with screenshots but will try and add some minimal code too.
Yes I would prefer it to be per language, and some of the other new features too like line spacing (without the limited choices combo box! I have to manually adjust it using export/import settings and editing the file). I find there is quite a difference depending on language.
That’s very cool. I notice that turning it on is under Options/Text Editor/General. Does that mean it works for native C++ as well as C#? Still, even if it works, it remains to be seen if it helps the coding experience. My fingers are crossed.
this is a contra productive feature to clean code.. helps only the messy..
Very nice! I’d like to see the if clause in addition to the else clause. Else, by itself, doesn’t provide much context.