1

Is there some way to tell less where to break pages?

I was hoping that ^L (form feed / page break) would do it, but found it doesn't. I tried the following:

The first page.
It is three lines
long.
^L
The second page.
Two lines only.
^L
The third page is short.
...

I'd like less to start showing line 1 at the top of the terminal, and after one key press line 5 should be at the top of the terminal. After another keypress it should be line 8.

As far as I can see in the help I can jump a line or a window (or to a specific line).

(If less can't do it, is there a pager that can?)

Magnus
  • 4,696

4 Answers4

1

From less help:

                     MOVING

 e  ^E  j  ^N  CR  *  Forward  one line   (or N lines).
 y  ^Y  k  ^K  ^P  *  Backward one line   (or N lines).
 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).
 ESC-SPACE         *  Forward  one window, but don't stop at end-of-file.
 d  ^D             *  Forward  one half-window (and set half-window to N).
 u  ^U             *  Backward one half-window (and set half-window to N).
 ESC-)  RightArrow *  Left  one half screen width (or N positions).
 ESC-(  LeftArrow  *  Right one half screen width (or N positions).

As a workaround you can use text editor (like vim to jump to desired line or whatever) in less by pressing v.

atype
  • 818
1

Emacs has functions with default keybindings for supporting movement between pages separated by ^L in files. Also the ability to narrow a buffer to only show the current page.

See https://www.emacswiki.org/emacs/PageBreaks

pelle
  • 183
0

Search for the form-feed character by typing / and Control-L. Then type n to move down to the next page, and N to move up to the previous page.

0

As far as I know, less can't currently do this. That said, it seems to still be actively maintained, so, I submitted an issue on github requesting this functionality. We'll see how that goes (I'm hoping for the best!).

I also don't know of any other pagers that do exactly what you want. That said, I feel it's worth pointing out that more (the predecessor to less) does have part of what you're looking for, in that it pauses output (waits for another press of [spacebar]) upon seeing a formfeed character. It doesn't clear the screen afterwards, so you won't get the "top of the terminal" behavior you're looking for, but you will at least get a situation where one must press a key between pages.

Hopefully one or both of these is helpful to you, if indeed you still have this need.

lindes
  • 470