5

Is it possible to enable "wrap around" in less for the search? This means: If the last occurrence of a pattern has been found, pressing n will start the search again at the beginning of the file (so you do not have to press g and then n).

4

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

  • So if I am in the middle of a file, there is no way to be sure that pattern doesn't occur anywhere other than typing /pattern and n and N or g and n? – wolf-revo-cats Jan 17 '16 at 11:50
  • That's all the manpage gives you. – Thomas Dickey Jan 17 '16 at 12:01
  • 1
    ggn is easily typed, basically, return to top, next... – lornix Jan 17 '16 at 21:07
  • It might be, but does nothing more than go to the top and search from the top, which was what OP wished to avoid. – Thomas Dickey Jan 17 '16 at 21:14
0

As a workaround, you can redefine the forward/backward search key mappings to jump to the begin/end of the file and then search.

Add these to the $HOME/.lesskey file:

#command
\eB back-search
\eF forw-search
/ noaction gg\eF
? noaction G\eB

Compile it with lesskey.

See man lesskey for default key mappings and actions.

Tested in version 530.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.