3

If I mark a line in less, the mark will lost when the current less session ends.

So, let's say, if I often check the bash man page for READLINE section, I have to search ^REA every time.

Seems like less doesn't have any config files. Is there a way to save the marks in less so I can use it for next time?

0

Not in the version of less I looked at. Another problem is that man may write to temporary files, so how would the marks line up between /tmp/man.sLCaUQkJ3k and /tmp/man.yuvNSUrFZo even if they were being saved?

We can cheat a little and use vim which does with suitable configuration save marks for future use, and also use the same filename for each man page. Note that a system-wide temporary directory would most likely be a very bad place to put static filenames, unless you like generating new CVE.

function mman {
   man "$1" | col -bx > "$HOME/tmp/man.$1"
   vim -R "$HOME/tmp/man.$1"
   #rm "$HOME/tmp/man.$1"
}

The generated page could either be removed immediately, or maybe a cron job cleans them up. Another problem is that man section names or other arguments to man are not supported, so this code may likely need to be complicated to handle man 3 rand the same as man rand (though those two may not be the same depending on your system and whether the OpenSSL rand man page intrudes).

  • Please specify your version of less. – agc Jul 27 '18 at 3:57
0

There are no way to preserve the marks across invocations... But:

So, let's say, if I often check the bash man page for READLINE section, I have to search ^REA every time.

less saves search history by default. It stores it in ~/.lesshst, which can be overridden by setting the $LESSHISTFILE environment variable to point to another file's path. So at least you can use that to search for a regexp you used before (assuming you're using that same one often.) I hope you might find that useful (in case you didn't know about it.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.