Consider the following file:
$ LESS= \less test
abc
def
abc
By default, searching /abc
in less
will jump to line 3 since /pattern
search starts at second line according to man 1 less
:
/pattern
[... snipped ...] The search starts at the second line displayed (but see the
-a and -j options, which change this).
-a
and -j
do not help.
It's annoying that I have to do a backward search (N) after each /pattern
search to make sure I have not missed anything important in the first line.
How do I make less
pattern search starts at first line displayed?
Edit:
less
version:
$ less --version
less 436
Copyright (C) 1984-2009 Mark Nudelman
less comes with NO WARRANTY, to the extent permitted by law.
For information about the terms of redistribution,
see the file named README in the less distribution.
Homepage: http://www.greenwoodsoftware.com/less
Best Answer
The most straightforward solution is to upgrade to less 441 or newer. From the changelog:
The
-a
and-j
option can cause the search to begin further than the topmost screen line, but I don't think they can cause the search to begin at the topmost screen line — that's why the-A
option was added (and made the default, apparently it was very popular).