#336570·VS Code

Search Editor: Allow choosing whether context lines appear before or after matches

Author: yuyosyCreated Sep 17, 2026Updated Sep 17, 2026

Problem

The Search Editor allows users to configure the number of context lines displayed around each match. However, the configured number is always shown on both sides of the matching line.

In some cases, only one side contains useful information. For example, a log entry might start with a matching severity line, followed by the relevant message and diagnostic details:

Severity: Error
Message: Failed to connect to the database
Host: example.internal
Retry count: 3

When searching for Severity: Error, only the lines after the match may be needed. To display three following lines today, the Search Editor also displays up to three unnecessary lines before every match. The reverse situation also occurs when the useful context precedes the matching line.

This produces additional noise, especially when reviewing many matches in a Search Editor.

Proposal

Allow users to choose the placement of context lines in the Search Editor:

  • Around — show context before and after the match, preserving the current behavior
  • Before — show context only before the match
  • After — show context only after the match

The existing context line count would apply to the selected placement. For example, with a context line count of 3:

  • Around: 3 lines before and 3 lines after
  • Before: 3 lines before
  • After: 3 lines after

Around would remain the default so that existing behavior and saved Search Editors remain compatible.

Scope

This option would apply only to the Search Editor. It would not change the behavior of the Search view or existing search providers.

Prototype

I have a prototype implementation ready in my fork.

https://github.com/user-attachments/assets/78bcf4a3-b954-4ffb-aabf-df1588b46023

The prototype:

  • Adds a compact context-placement menu next to the existing context controls
  • Supports Around, Before, and After
  • Persists the selected placement in saved Search Editors
  • Supports the placement through Search Editor command arguments
  • Preserves Around as the default for existing Search Editors
  • Keeps the existing search service behavior unchanged and filters the displayed context in the Search Editor

The last point keeps the implementation scoped to the Search Editor. It may retrieve some context lines that are later omitted, but avoids changing the general search service and search-provider contracts.

Questions

  • Would a compact placement menu next to the existing context controls be an appropriate interaction?
  • Should this remain a Search Editor-specific presentation option, or should directional context be supported by the underlying search service?

I have a prototype implementation ready in my fork. Would an external contribution for this feature be considered?