Search in less with wrap-around at EOF

Probably not: the manual page for less does not mention wrapping, and the description of the search feature does not hint it is possible.


Yes, it is possible since release v568.

There is a patch (full disclosure: I wrote it) for this exact feature included since v568. But note that your OS/package manager likely still provides an earlier stable version, not the latest release. So, you may have to build less from source to be able to use the feature right now.

The patch adds the ^W search modifier which allows wrap-around search within the current file. From the manual:

       /pattern
              (...)

              ^W     WRAP around the current file.  That  is,  if  the  search
                     reaches  the  end  of  the current file without finding a
                     match, the search continues from the first  line  of  the
                     current file up to the line where it started.

If you want this to be default behavior, you could add something like the following to you config file (probably located at ~/.lesskey, see man lesskey for details):

#command
/ forw-search ^W
? back-search ^W

Tags:

Less