Why do less search result lines disappear/reappear?

user123992

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

Wouter Verhelst

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).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why is pagination on search result not working?

From Dev

How do I include newlines in a search in less?

From Dev

Make "less" jump point to center of search result rather than top

From Dev

Why do two statements result in different result?

From Dev

Why search query not showing any result in PHRETS?

From Dev

How to force aptitude to display each search result in multiple lines?

From Dev

Why do bools take less memory in an array?

From Dev

Why do vim and less have such similar keybindings?

From Dev

How do I write all lines from less to a file?

From Dev

How do I make less STOP chopping long lines by default?

From Dev

Why does my CSS continue to search for code in .less files?

From Dev

Why does my CSS continue to search for code in .less files?

From Dev

How do I highlight a search result in tmux?

From Dev

how to do a vim search inverse search for all lines with out text

From Dev

How do you run `less` and have it run a search pattern automatically?

From Dev

How do I search a file using "less" for a value with a decimal point?

From Dev

Why would these three lines of code result in the definition of a Javascript "class"?

From Dev

Why aren't these lines of code returning any result?

From Dev

Why aren't these lines of code returning any result?

From Dev

Why do gray lines appear around the paths?

From Dev

Why do cat and more wrap lines differently?

From Dev

Why are new lines (CRLF) removed when a search-and-replace is performed?

From Dev

Why grep search '0,^M$' return empty lines?

From Dev

Why do transparent materials result in occlusion?

From Dev

Why do sapply() and lapply() have same result?

From Dev

Why do I get the following result?

From Dev

Why does slice::binary_search return an incorrect result?

From Dev

How do you search and replace multiple lines in KDE Kate?

From Java

Why do tuples take less space in memory than lists?

Related Related

  1. 1

    Why is pagination on search result not working?

  2. 2

    How do I include newlines in a search in less?

  3. 3

    Make "less" jump point to center of search result rather than top

  4. 4

    Why do two statements result in different result?

  5. 5

    Why search query not showing any result in PHRETS?

  6. 6

    How to force aptitude to display each search result in multiple lines?

  7. 7

    Why do bools take less memory in an array?

  8. 8

    Why do vim and less have such similar keybindings?

  9. 9

    How do I write all lines from less to a file?

  10. 10

    How do I make less STOP chopping long lines by default?

  11. 11

    Why does my CSS continue to search for code in .less files?

  12. 12

    Why does my CSS continue to search for code in .less files?

  13. 13

    How do I highlight a search result in tmux?

  14. 14

    how to do a vim search inverse search for all lines with out text

  15. 15

    How do you run `less` and have it run a search pattern automatically?

  16. 16

    How do I search a file using "less" for a value with a decimal point?

  17. 17

    Why would these three lines of code result in the definition of a Javascript "class"?

  18. 18

    Why aren't these lines of code returning any result?

  19. 19

    Why aren't these lines of code returning any result?

  20. 20

    Why do gray lines appear around the paths?

  21. 21

    Why do cat and more wrap lines differently?

  22. 22

    Why are new lines (CRLF) removed when a search-and-replace is performed?

  23. 23

    Why grep search '0,^M$' return empty lines?

  24. 24

    Why do transparent materials result in occlusion?

  25. 25

    Why do sapply() and lapply() have same result?

  26. 26

    Why do I get the following result?

  27. 27

    Why does slice::binary_search return an incorrect result?

  28. 28

    How do you search and replace multiple lines in KDE Kate?

  29. 29

    Why do tuples take less space in memory than lists?

HotTag

Archive