10

Is it possible to scroll past the bottom in less?

Ideally, I'd like to be able to see the last line of the file I am viewing at the top of my terminal window (the rest of the screen may be filled with tildes (~), which mean empty line/nothing to see here in less).

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164
Mateusz Piotrowski
  • 4,623
  • 5
  • 36
  • 70

2 Answers2

14

Yes, using J (as in ShiftJ). So you can go to the end of the file with G, then scroll down past the end with J until the last line of the file is at the top of the screen (less won’t let you scroll any further).

K and Y do the same at the top of the file, scrolling up past the beginning until the first line is at the bottom of the screen.

As David Ongaro points out, you can use repeat specifiers to avoid having to press J multiple times: G99J will thus scoll down until the last line is at the top of the screen (unless your terminal has a very large number of rows).

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164
  • 1
    Yes! They used the word _beyond_ instead of _bottom_: that's why I could not find it. Also, I thought that there should be a flag for it. Nevertheless, this is the correct answer. Thanks! I'll accept it ~soon. :) – Mateusz Piotrowski Mar 10 '18 at 19:14
  • Seems with `100J` one can avoid hitting `J` repeatedly. – David Ongaro Mar 11 '18 at 06:03
2

The -c option also creates "scroll past EOF" behavior in some circumstances.

Without -c, when you are near the end of file (the remaining part after the part you currently see is less than a screen height), the space scrolls down just enough to put the last line of the file on the last line of the screen. space can be equivalent to j if there's only one more line to show.

With -c, as long as you aren't at EOF already, space always scrolls forward a full screen height. The top line on the screen after space will be the line after the one that was at the bottom before the space. This can leave some portion of the screen unused, and it is filled with the ~ markers.

In -c mode, to make the last line the only visible line, G K space is all you need.

...unless the last line in the file is wider than the screen width, in which case you need to repeat the K.