Sticky Scroll now in preview

Leah Tran

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.

C# example

C++ example

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.

30 comments

Discussion is closed. Login to edit/delete existing comments.

  • Jason Baginski 11

    It’s very nifty but I couldn’t possibly ever see using it as screen real estate is a premium for me.

    Might I suggest having an option for a hot key to just preview it? For example, I’m typing along and go “I’m a little lost where I am”, being able to hit ctrl+whatever and see this sort of preview letting me know where I am in my {} stack would be great to remind me. Then as soon as I start typing or click somewhere it goes away so I can continue what I was doing.

    • Kirsan 5

      Agreed, hot key will be very helpful.

  • Steven Rasmussen 13

    This looks very promising! One thing I would suggest is to make it configurable so that you could turn off the ‘Namespace’ and ‘Class’ stickiness. Most of the time we are dealing with a single namespace and class per file. Another option would be to make it such that those only appear if the file contains more than a single namespace or class. Thanks!

    • Vaclav Elias 3

      I agree. I don’t really bother about the Namespace name, and it doesn’t make sense to show class in my case if there is just one class per file. Also, it is easy to jump on the top of the file, without clicking the class name.

      Also, if there is one method, it could be optional.

      • Jesse Liberty 4

        I love this feature, but agree about namespace and probably about class as well. Ideally it would know if there is >1 class in a file and only show it if there is.

    • Johan Eriksson 3

      doesn’t happen to me, guess its because I’m using file-scoped namespaces ?

    • Luc Nanquette 1

      I agree. This could be easily solved by showing the last scope levels instead of the first scope levels. If I set the maximum sticky lines to 3, only the last 3 scope levels should be shown.

  • Thierry PĂ©lissier 0

    Salut,
    Personnellement, moi ca plante Visual Studio quand je coche ou décoche la case.

    Hi,
    Personally, it crashes Visual Studio when I check or uncheck the box.

      • Thierry PĂ©lissier 1

        C’est fait.
        It’s done.

        • Thierry PĂ©lissier 1

          answer developercommunity.visualstudio :
          A fix for this issue has been internally implemented and is being prepared for release. We’ll update you once it becomes available for download.

          réponse developercommunity.visualstudio :
          Un correctif pour ce problème a Ă©tĂ© implĂ©mentĂ© en interne et est en cours de prĂ©paration pour la publication. Nous vous tiendrons au courant dès qu’il sera disponible au tĂ©lĂ©chargement.

  • Mark Dell 4

    Seems very cool, and I agree with the suggestions on this page, however, I noticed how things like the Else statement are handled which can make it difficult to see which Else you are in.
    Perhaps the corresponding If or maybe ElseIf statement(s) should also be shown, maybe only as a tooltip, similar to how references show the relevant section of code.
    Also, it sounds like it does not support VB, which is unfortunate. I would like to see that language included.

    • Thierry PĂ©lissier 1

      Effectivement, VB n’est pas reconnu. J’ai testĂ©.
      Indeed, VB is not recognized. I have tested it.

      • Jens Samson 1

        Once again, we are 2nd class citizens.

        • Oleg TkachenkoMicrosoft employee 2

          I agree sticking Else without If is somewhat confusing…

          But Sticky Scrolling does support VB! In fact, Sticky Scrolling supports any language already supporting Structure Guides (vertical lines). If you don’t see it working in VB, please report using Help/Send Feedback/Report a Problem, it’s not a known issue.
          Thank you for the feedback!

          • CJay 0

            I also cannot get it to work in VB and don’t see any other reports of this. I will submit feedback.

  • James Lear (Portfolion Planning) 0

    Very nice! I’d like to see the if clause in addition to the else clause. Else, by itself, doesn’t provide much context.

  • Criostal Taranis 0

    this is a contra productive feature to clean code.. helps only the messy..

  • Paul Topping 0

    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.

  • David N 0

    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#.

    • Oleg TkachenkoMicrosoft employee 0

      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?

      • David N 0

        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.

  • Edy Kusnandar 0

    thank info , i like your artikel

  • d3c0d3d 0

    The feature is cool, but I had to turn it off because it breaks VS when you’re working with javascript code.

    • Leah TranMicrosoft employee 0

      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?

  • Hilton Varian 0

    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 gun Id;
    private string Gun;
    private float Distance;
    {
    }
    public Guns=struct:Weapons
    do Gun Stuff etc;

    {
    }

    Why Can you not put that in the Next update in C#? Structures Can use Interfaces and Record Can Use Interfaces as Long as You Fill in the Method and Functions?
    so Whey Cant Structures Use Records? in Inheritance? Would it not Help in Database Development? Make the Structures so it Can only Inherit Record Structures?

  • Dwayne Robinson 0

    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).

  • Nouman Abbas 1

    Thanks!
    Much Needed feature!
    But does it work for others than C#?

    • Oleg TkachenkoMicrosoft employee 0

      Yes, Sticky Scrolling works in any language that already supports Structure Guides (vertical gray dashed lines).

Feedback usabilla icon