Why does “less” sometimes forget its history

command historyless

I set and exported $LESSHISTFILE and $LESSHISTSIZE but if I perform a search in one less session, close, reopen it and try to repeat my last search I get "No previous regular expression (press RETURN)".

It works as expected in Ubuntu 14.04 but not in Fedora release 7. Any suggestion?

It's writing to $LESSHISTSIZE. I get the same text written to the history file on both Ubuntu and Fedora. Below I started with an empty history file and then executed cal | less. I searched for "xxx" while in less. But when I exit and rerun the less command it gives me the error message if try to repeat the search with just the / command.

$ cal | less
$ ls -l  $LESSHISTFILE
-rw------- 1 cs cs 40 Aug  4 14:23 .lesshist
$ cat  $LESSHISTFILE
.less-history-file:
.search
"xxx
.shell
$ 

Maybe it's because the version on Fedora is so old.

$ less --version
less 394
Copyright (C) 1984-2005 Mark Nudelman

Best Answer

Ubuntu 14.04 has less 458, and Fedora 7 has less 394. The NEWS file between those versions is the place to look:

            Major changes between "less" versions 394 and 406

    * Allow decimal point in number for % (percent) command.

    * Allow decimal point in number for -j option (fraction of screen height).

    * Make n command fetch previous pattern from history file on first search.

For that, you have to look at the sources (I'm looking at the file from less 451), because the online history doesn't go back that far. You can get older versions from ftp://ftp.gnu.org/gnu/less/

Since answering this in 2016, the RCS for less was exported to git here, apparently in mid-2017, and one can point more accurately to the change (early 2007). Exactly when the switch was done is unclear, since the repository commits are unverified.

Related Question