7

Just like this question: I want to open a file with e.g., less -Sx32 file.dat, but as I scroll down, keep the top line locked in place. How can I do this with less?

3
  • What does that -Sx32 do?
    – jarno
    May 28, 2020 at 9:06
  • 1
    @jarno it turns off word wrapping and sets the tab size to 32. It is convenient for viewing large tab-separated data files, which are common in data science. Jun 6, 2020 at 13:09
  • Oh, yes it is the same as -S -x32.
    – jarno
    Jun 6, 2020 at 13:36

2 Answers 2

6

It is now possible since less v600 (released on 2022-01-07)

With the --header option, so in your case less --header 1 myfile would keep the first line always displayed. Excerpt from the less v608 manpage:

--header

Sets the number of header lines and columns displayed on the screen. The value may be of the form "N,M" where N and M are integers, to set the header lines to N and the header columns to M, or it may be a single integer "N" which sets the header lines to N and the header columns to zero. When N is nonzero, the first N lines at the top of the screen are replaced with the first N lines of the file, regardless of what part of the file are being viewed. When M is nonzero, the characters displayed at the beginning of each line are replaced with the first M characters of the line, even if the rest of the line is scrolled horizontally.

Related: https://stackoverflow.com/a/71308346/1077650

How to install, configure and compile a new version of less

Get the latest RECOMMENDED version here and follow the instructions there.

# prerequisites on Debian 11.6 bullseye - see NB notes below
sudo apt install gcc make libncurses5-dev

# download, configure, compile
wget http://greenwoodsoftware.com/less/less-608.tar.gz
tar xzvf less-608.tar.gz
cd less-608
sh configure
make

# Then you can test it!
./less --version
./less --header 1 myfile

NB: in order to compile less, you will need to have gcc and make packages installed.

NB: if configure failed with something like Cannot find terminal libraries, you need to install libncurses5-dev package (or similar)

0

It requires some changes to less. There exists an enhancement request here in GitHub. If it was implemented, you could use something like

less --freeze-pane 0,1 file.dat

to do what you want.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .