When skimming through a file with less, I'm able to see all lines just fine.

When I do a search and then go for the next result with n, sometimes a highlighted result is shown on the top line, and sometimes there's nothing highlighted at all. This puzzled and annoyed me, so I did some experimentation.

What I found is that, when less gets search results on a line that would be wrapped, it is instead displaying the line following the search result, and not displaying the result line at all. In the image below, for example, it displayed the blue-highlighted "Contact Load..." line at the top of the page.

Missing search result

If I use up arrow to go look for the missing line, the search result still doesn't appear. Instead, less double-displays the top line.

If, however, I use down arrow to get the first line off the top of the screen, then use up arrow to return to where it was, poof! My missing search result suddenly appears.

Search result showing

I've got my work-around, but my question is 1) why is this happening, and 2) is there some less startup flag I can use to avoid it?

In case it helps diagnose the problem, I'm running less -NFRW


1 Answer 1


This is a (very old) bug in less which seems to be related to line counting when line folding is on. There isn't much you can do (other than contacting the developers and asking them to fix it...)

My personal workaround has been to use -S to tell less to not fold lines. It seems to go away then. However, if the thing you're searching for is in the bit that would have been folded down had you not used -S, you'll need to scroll to the right to see it. Note that you can specify additional options when less is already started, by just entering them at the : prompt.

Alternatively, you could switch away from less to a different pager. If you just want to look at a file, view (part of the vim suite) may work. Basically, if you call view, you're running vim, but telling it to only open files in read-only mode (so you can't accidentally modify it).

  • I just checked out view (hadn't seen that one) and it's far clearer with the vim cursor. It looks like there is no continuous refresh, but I can do :edit in vim/view for those situations. Thank you!
    – user123992
    Dec 18, 2015 at 15:59

You must log in to answer this question.