What is Sticky Scroll for Visual Studio?

When you work in a large code file or scroll through an unfamiliar codebase, sometimes it can be difficult to tell where you are in the code. With Sticky Scroll, you can stick scopes to the top of the editor so that they're always in view while you scroll through your code. Visual Studio 2022 version 17.5 and later support Sticky Scroll.

Supported programming languages

Multiple code formats are supported, including C#, C++, XAML, and JSON.

Here's an animated example of Sticky Scroll in a C# file:

An animation of the Sticky Scroll feature being used in C# code.

Here's an animated example of Sticky Scroll in a C++ file:

An animation of the Sticky Scroll feature being used in C++ code.

Turn Sticky Scroll on or off

Use the following steps:

  1. From the Visual Studio menu bar, select Tools > Options > Text Editor > General.
  2. In the Sticky scroll section, select, or unselect, the Group the current scopes within a scrollable region of the editor window option.
  3. Select OK.

If you want to turn Sticky Scroll off, you can do so from the editor by right-clicking in the Sticky Scroll header area and then selecting Sticky Scroll.

Important

If you're using C# and Sticky Scroll isn't working for you, try this workaround. Select Tools > Options > Text Editor > C# > Advanced. Next, in the Block Structure Guides section, enable the following options.

Option Description
Show guides for declaration level constructs Affects namespaces, classes, and method initializations
Show guides for code level constructs Affects conditionals and loops

How Sticky Scroll works

You can use Sticky Scroll to stick scopes such as namespaces, classes, methods, loop initialization statements, and conditionals.

And, you can jump directly to a line of code by clicking its reference in the Sticky Scroll header.

An animation of the single-click option in the Sticky Scroll header that takes to code.

How to configure Sticky Scroll

You can change how Sticky Scroll works by changing its scope and the number of lines it includes in that scope.

Inner and outer scopes

Based on your preference, you can change the scope of what Sticky Scroll shows you. Set by default, the outer scope option shows the higher-level scopes that come from the top of the file.

An animation of the Sticky Scroll with outer scopes selected.

But sometimes, the namespace and class name match the file name. When information such as this is obvious, you might not want to give up two lines of vertical space at the top of your file. Then, you can change to the lower-level inner scope option, which pushes out higher-level scopes as you scroll through deeply nested code.

An animation of the Sticky Scroll with inner scopes selected.

You can configure whether to prioritize outer or inner scopes when the set number of scopes exceeds the maximum. From the Visual Studio menu bar, select Tools > Options> Text Editor > Sticky scroll, and then select Prefer outer scopes or Prefer inner scopes.

Screenshot of the inner and outer scope options for Sticky Scroll.

To learn more about Sticky Scroll in Visual Studio, explore the following resources: