Skip to content

[BUG] Ctrl+R history search matches wrong fields when extended_history is enabled #1019

@alealv

Description

@alealv

Describe the bug

Ctrl+R history search returns wrong results when extended_history is enabled. The query matches against the wrong fields instead of the actual command text.

Root cause

Commit c0a9be6 changed "today " to "today@", merging date and time into a single field. But it also bumped n from 3 to 4.

The awk filter transforms fc output from 4 fields into 3:

# Before awk (4 fields): index, date, time, command
12254  2026-03-29 15:58  ls -la /tmp

# After awk (3 fields): index, formatted_date, command
12254  today@15:58	ls -la /tmp
12254  2026-03-28	git status

With n=4, -n4.. tells sk to match on field 4 onwards, which is past the command. SK matches against nothing, returning random results.

To Reproduce

# n=4 (current, broken) — "ls" match is missing:
printf '\033[2m1\033[0m \033[32mtoday@15:58\033[0m\tls -la /tmp\n\033[2m2\033[0m \033[32mtoday@15:57\033[0m\tgit status\n' \
  | sk -n4.. --ansi --filter "ls"

# n=3 (fixed) — correct result appears:
printf '\033[2m1\033[0m \033[32mtoday@15:58\033[0m\tls -la /tmp\n\033[2m2\033[0m \033[32mtoday@15:57\033[0m\tgit status\n' \
  | sk -n3.. --ansi --filter "ls"

Expected behavior

History search should match against the command text.

Suggested fix

In shell/key-bindings.zsh:

-    n=4
+    n=3

The awk filter merges date+time into one field (today@HH:MM or YYYY-MM-DD), so the command is field 3, not 4.

Environment:

  • OS: Darwin 25.3.0 arm64 (macOS)
  • skim version: sk 4.0.1
  • Shell: zsh 5.9

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions