tags:

views:

124

answers:

3

Thank you to Alex in showing me how to put a percentage sign in Less!

I now aim to show the percentage sign also when you run, for example, the command

man emacs

If you run it, you get 'byte 3300' for instance.

Alex's answer suggests me that we need to make a separate shell function by

man "$1"| col -b > /tmp/manual
less /tmp/manual

where $1 refers to the first parameter.


The new problem is at the thread. Thanks to Yuliy for the crux move!

+2  A: 
export LESS="-m"

More generally, the LESS environment variable may contain options equivalent to command line flags you could explicitly pass when running less -- here, the -m option that tells it to prompt more richly (including the percentage, as you asked). You could pass also more than one option within that single environment variable by ending each with a $. For much more info, see less's manpage.

Edit: it is of course possible (depending on how you're using less, e.g. if you're piping to it rather than calling it on a file) that less doesn't know the total size it will be displaying, in which case of course it can't show the % -- in that case it will prompt with what little info it does have, e.g., how much text has it shown so far. For example, man does use less that way, by piping.

So, if your specific need is to see the % in man (rather than when calling less directly on a file) you need to use an "alternate pager" (environment variable MANPAGER or switch -P on the man command line) which is a simple script that saves man's output to a temp file and then uses less on the latter. (That may lose man's own "colorization" unless you play yet further and deeper tricks, etc, etc -- similarly you might use the "preformat pages" option of man and uncompress such a preformatted page to a tempfile on which to run less, etc, but this is starting to become a somewhat complex "simple script";-).

Alex Martelli
@Alex: It seems that something is wrong in my Less, since I see: http://files.getdropbox.com/u/175564/bugLess.png. When I go to the end of the manual the percentage sign starts to work. --- I disabled my .zshrc so the bug cannot be in it.
Masi
It's possible (depending on how you're using less, e.g. if you're piping to it rather than calling it on a file) that less doesn't *know* the total size it will be displaying, in which case of course it can't show the %. Here, let me edit the answer with this remark for completeness.
Alex Martelli
@Alex: Please, see my attempt to your suggestions in my question.
Masi
Your script is correct so I don't understand (2). Nor do I understand what this has to do with emacs or vim so the other points are also mysteries to me, particularly in the context of a question about "making less indicate location in percentage". Why not open several separate questions about (1), emacs stuff, vim stuff, and whatever else? I can try to help with (1) if I see it in a separate question (if you consider my answer to this one question good enough to accept, otherwise I'll know you're just too hard to please;-) but surely won't tackle the emacs one, for example;-).
Alex Martelli
You are right: the last questions are not relevant anymore. -- I fixed my post.
Masi
A: 

I have this in my environment. It'll print <filename> - Lines X-Y of Z at the bottom, or at least as much of that information as it has.

export LESS='-P?f%f - .?ltLine?lbs. %lt?lb-%lb.?L of %L.:?pt%pt\%:?btByte %bt:-...'
John Kugelman
@John: I use OS/X. Your code have no effect in my Less. It only removes my line numbers set by % export LESS='-N' %
Masi
+1  A: 

To add to Alex Martelli' answer:

Note that you can also pass any command line parameter to less at runtime, by just typing it (including the -), followed by enter key. So you can just type

-m<Enter>

into a running less to toggle the long prompt.

This is especially useful for options that need to be changed at runtime, e.g. -S (line folding on/off).

sleske
@sleske: Should the option -S give folds similar as in Vim? --- It seems to remove duplicate empty lines by an empty line.
Masi
No, -S (Shift-S) just wraps lines, instead of cutting them off at the edge of the screen. What you were seeing was -s (just small s), which indeed removes duplicate empty lines.
sleske