less command: b/f vs w/s

About the less and according with:

indicates the following:

f ^F ^V SPACE * Forward one window (or N lines).
b ^B ESC-v *    Backward one window (or N lines).
z * Forward one window (and set window to N).
w * Backward one window (and set window to N).

Enabling the line numbers – with -N – for example for man less itself, I can see that b/f works/behaves the same than w/z it about the amount of content/lines moved up/down by either window or page.

Question

  • What is the difference between b/f vs w/z?

normally I use the first pair, but when use the second pair?

Extra Question

  • What does and set window to N mean?

I am assuming it is the expected difference that makes w/z different against b/f

Asked By: Manuel Jordan

||

I’ll try my best to explain with an example.

Open a long text file with less, something with obvious lines.

Now type 4z, and you will see that 4 lines have shifted down.

Type z and another 4 lines have moved.

That 4z has told less that you want the window size to be set to 4.

Once you have set the window size, all options (f,b,z or w) will now use that as the window size when moving through the text.

The difference is when f and b are used like this, they do not set the window size, they only move by that N number of lines.

Summing up with an example:

  • 8f: Move through the document 8 lines.
  • 9b: Move backwards through the document 9 lines.
  • f or z: Move one "window size" through the document.
  • b or w: Move backwards one "window size" through the document.
  • 6z: Move through the document 6 lines and set the "window size" to 6 lines. Using f,b,z or w after this will shift the document 6 lines.
  • 3w: Move backward through the document 3 lines and set the "window size" to 3 lines. Using f,b,z or w after this will shift the document 3 lines.

To reset the window size, you can type -+z (then enter).

Hope that helps.

Answered By: Tigger
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.