less icon indicating copy to clipboard operation
less copied to clipboard

[RFE] always show buffer content on start when pattern specified via CLI matches nothing

Open ryenus opened this issue 3 years ago • 2 comments

Version: less 580

Currently, in case the search pattern is passed via the command line options, and if there's no match, like the case with the following command:

echo abc | less +/d

In this case, upon starting, less doesn't show the buffer content, namely abc in this case, instead it only displays the error message:

Pattern not found (press RETURN)

It would be better that the buffer content is also made visible before the above error message is dismissed.

ryenus avatar Mar 10 '21 03:03 ryenus

Same with less --pattern=foo (which is really alias for +/foo).

workarounds I discovered:

  • Pressing RETURN proceeds to show the file content. (Same as "Pattern not found" message behaves after interactive search — just less obvious if the message is all you see at first... I mean, it says "press RETURN" right there in the message, but it hadn't occurred to me :see_no_evil:)
  • less +r --pattern=foo — r does repaint. It may still show "Pattern not found", but at least you'll see (the first screen of) the text.
  • if your goal of searching is highlighting, not movement, try less +r --pattern='foo|$'. The |$ makes it match the empty string at end of any line, preventing "Pattern not found" (except on entirely empty file). Naturally, it breaks the n/p keys as every line will match.

I still wish paint-before-message was default behavior.

cben avatar Jan 24 '23 00:01 cben