1

I use less version 590 (GNU regular expressions).

I use

export LESSFILE="/root/.lesshst_for_manpages"
export MANPAGER="pager --save-marks -I"
man -L en <<somemanpage>>

... but --save-marks appears to have no effect when setting marks in manuals (using the m command in the pager). When reading the same manual again, the pager does not seem to remember the previously set marks.

What can I do?

1
  • A simple way to get back to the manual where you left off is to number the lines (using -N<ENTER> ) and make a note of the line number. Alternatively copy one of the lines on the screen (say top line) onto clipboard and when you come back to the same manpage press / and paste. Yet another way is to copy the manpage to a local file and then use less command which allows marking. Commented Jun 16, 2024 at 9:40

1 Answer 1

1

When you use less with --save-marks, set a few marks in the file called file, and quit the pager, your ~/.lesshst files will contain a few lines of information about these marks:

$ cat ~/.lesshst
.less-history-file:
.mark
m a 1 6659 /home/myself/tmp/file
m c 1 33259 /home/myself/tmp/file

Here, I've set the a and c marks at different locations using the m command in less, in the file ~/tmp/file. As you can see, the two marks are tied to the pathname of the file. This allows us to view the same file in less at some later time, and go to either the a or c mark using the ' command.

Setting the a and b marks in another file will update the saved a mark and add the b mark:

$ cat ~/.lesshst
.less-history-file:
.mark
m a 1 46559 /home/myself/tmp/other-file
m b 1 13309 /home/myself/tmp/other-file
m c 1 33259 /home/myself/tmp/file

Note that the a mark in the ~/tmp/file file no longer exists. The point is that the marks are locations in files at particular pathnames.

When you use less as a pager for reading manuals, what is the pathname of the text document you read? You can get this information using either the = command, the :f command, or by pressing Ctrl+G in the pager. A hint: There is no filename.

The reason there is no filename is because the manual, i.e., the text document that less is displaying, is coming from a pipe. It's similar to using less like so:

$ cat file | less --save-marks

... and if you do that, and set a mark, you will notice that the mark is removed from the .mark section of the ~/.lesshst.

In short, less cannot remember a mark in a piped document. This is why marks are not saved when using less for viewing manuals. Furthermore, any marks that you try to set in a manual will be cleared from your ~/.lesshst file.

9
  • Why not? Every man page has a unique name that can be used as an ID, where is the difference? It doesn't matter where the input comes from if it's DB, file, or pipe until it can be uniquely identified, this ID can be used to save marks. I lack this feature so much for man pages. Commented Oct 11, 2024 at 14:25
  • 1
    @SilverZachara When less reads the data from a pipe, it does not have any information about where the data comes from. How could it have? Commented Oct 11, 2024 at 15:41
  • 1
    @SilverZachara That's man supplying the less pager a string to use as prompt on your system (not on mine). You can do the same with less directly: less -Ps'Hello Silver!' somefile. The actual prompt string used is documented in the man(1) manual. This has nothing to do with the name of the file that less is showing you (it is still unknown to less because it's comes from a pipe, or it's a temporary file somewhere under /tmp). Note that marks saved by the m command are saved with the filename, not the prompt string. Commented Oct 11, 2024 at 20:49
  • 1
    @SilverZachara That would still not help as the mark is being saved for a particular filename. Commented Oct 11, 2024 at 22:08
  • 1
    @SilverZachara It's not a question of why it can't be used or not. The implementation of less does not use it. You would have to patch the code to do what you want. It's most definitely possible to change the behaviour of less, but it does not change by magic just because you want it to. Commented Oct 12, 2024 at 7:51

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.