xref: /openbsd-src/usr.bin/less/less.1 (revision 8500990981f885cbe5e6a4958549cacc238b5ae6)
1.\"	$OpenBSD: less.1,v 1.7 2003/11/30 14:27:52 jmc Exp $
2.\"
3.\" Copyright (C) 2002  Mark Nudelman
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
9.\"    notice, this list of conditions and the following disclaimer.
10.\" 2. Redistributions in binary form must reproduce the above copyright
11.\"    notice in the documentation and/or other materials provided with
12.\"    the distribution.
13.\"
14.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
15.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE
18.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
20.\" OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
21.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
23.\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25.\"
26.Dd January 17, 2003
27.Dt LESS 1
28.Os
29.Sh NAME
30.Nm less , more
31.Nd view files on a crt
32.Sh SYNOPSIS
33.Nm less No | Nm more
34.Fl \&?
35.Nm less No | Nm more
36.Fl -help
37.Nm less No | Nm more
38.Fl V
39.Nm less No | Nm more
40.Fl -version
41.Nm less No | Nm more
42.Bk -words
43.Op Fl Oo Cm + Oc Ns Cm aBcCdeEfFgGiIJLmMnNqQrRsSuUVwWX~
44.Op Fl b Ar space
45.Op Fl h Ar lines
46.Op Fl j Ar line
47.Op Fl k Ar keyfile
48.Op Fl o | O Ar logfile
49.Op Fl p Ar pattern
50.Op Fl P Ar prompt
51.Op Fl t Ar tag
52.Op Fl T Ar tagsfile
53.Op Fl x Ar tab,...
54.Op Fl y Ar lines
55.Op Fl Oo Cm z Oc Ar \ \&lines
56.Op Fl # Ar shift
57.Xo Oo Cm \+ Ns Oo Ns Cm \+ Ns
58.Oc Ar cmd
59.Oc
60.Xc
61.Op Fl -
62.Op Ar filename ...
63.Ek
64.Pp
65.\" (See the
66.\" .Sx OPTIONS
67.\" section for alternate option syntax with long option names.)
68.Sh DESCRIPTION
69.Nm
70is a program similar to the traditional
71.Xr more 1 ,
72but which allows backward movement in the file as well as forward movement.
73Also,
74.Nm
75does not have to read the entire input file before starting,
76so with large input files it starts up faster than text editors like
77.Xr vi 1 .
78.Nm
79uses termcap (or terminfo on some systems),
80so it can run on a variety of terminals.
81There is even limited support for hardcopy terminals.
82(On a hardcopy terminal, lines which should be printed at the top
83of the screen are prefixed with a caret.)
84.Pp
85This version of
86.Nm
87also acts as
88.Xr more 1
89if it is called as
90.Nm more .
91In this mode, the differences are in the prompt and that
92.Nm more
93exits by default when it gets to the end of the file.
94Commands are based on both traditional
95.Nm more
96and
97.Xr vi 1 .
98Commands may be preceded by a decimal number,
99called N in the descriptions below.
100The number is used by some commands, as indicated.
101.Sh COMMANDS
102In the following descriptions, ^X means control-X.
103ESC stands for the ESCAPE key; for example ESC-v means the
104two character sequence "ESCAPE", then "v".
105.Bl -tag -width XXXX
106.It Ic h | H
107Help: display a summary of these commands.
108If you forget all the other commands, remember this one.
109.It Ic SPACE | ^V | f | ^F
110Scroll forward N lines, default one window (see option -z below).
111If N is more than the screen size, only the final screenful is displayed.
112Warning: some systems use ^V as a special literalization character.
113.It Ic z
114Like SPACE, but if N is specified, it becomes the new window size.
115.It Ic ESC-SPACE
116Like SPACE, but scrolls a full screensful, even if it reaches
117end-of-file in the process.
118.It Xo
119.Ic RETURN No \&| Ic ^N No \&|
120.Ic e No \&| Ic ^E No \&|
121.Ic j No \&| Ic ^J
122.Xc
123Scroll forward N lines, default 1.
124The entire N lines are displayed, even if N is more than the screen size.
125.It Ic d | ^D
126Scroll forward N lines, default one half of the screen size.
127If N is specified, it becomes the new default for subsequent d and u commands.
128.It Ic b | ^B | ESC-v
129Scroll backward N lines, default one window (see option -z below).
130If N is more than the screen size, only the final screenful is displayed.
131.It Ic w
132Like ESC-v, but if N is specified, it becomes the new window size.
133.It Xo
134.Ic y No \&| Ic ^Y No \&|
135.Ic ^P No \&| Ic k No \&|
136.Ic ^K
137.Xc
138Scroll backward N lines, default 1.
139The entire N lines are displayed, even if N is more than the screen size.
140Warning: some systems use ^Y as a special job control character.
141.It Ic u | ^U
142Scroll backward N lines, default one half of the screen size.
143If N is specified, it becomes the new default for subsequent d and u commands.
144.It Ic ESC-) | RIGHTARROW
145Scroll horizontally right N characters, default half the screen width
146(see the -# option).
147If a number N is specified, it becomes the default for future
148RIGHTARROW and LEFTARROW commands.
149While the text is scrolled, it acts as though the -S option (chop lines)
150were in effect.
151.It Ic ESC-( | LEFTARROW
152Scroll horizontally left N
153characters, default half the screen width (see the -# option).
154If a number N is specified, it becomes the default for future
155RIGHTARROW and LEFTARROW commands.
156.It Ic r | ^R | ^L
157Repaint the screen.
158.It Ic R
159Repaint the screen, discarding any buffered input.
160Useful if the file is changing while it is being viewed.
161.It Ic F
162Scroll forward, and keep trying to read when the end of file is reached.
163Normally this command would be used when already at the end of the file.
164It is a way to monitor the tail of a file which is growing
165while it is being viewed.
166(The behavior is similar to the "tail -f" command.)
167.It Ic g | < | ESC-<
168Go to line N in the file, default 1 (beginning of file).
169(Warning: this may be slow if N is large.)
170.It Ic G | > | ESC->
171Go to line N in the file, default the end of the file.
172(Warning: this may be slow if N is large,
173or if N is not specified and standard input, rather than a file,
174is being read.)
175.It Ic p | %
176Go to a position N percent into the file.
177N should be between 0 and 100.
178.It Ic {
179If a left curly bracket appears in the top line displayed
180on the screen, the { command will go to the matching right curly bracket.
181The matching right curly bracket is positioned on the bottom
182line of the screen.
183If there is more than one left curly bracket on the top line, a number N
184may be used to specify the N-th bracket on the line.
185.It Ic }
186If a right curly bracket appears in the bottom line displayed on the screen,
187the } command will go to the matching left curly bracket.
188The matching left curly bracket is positioned on the top
189line of the screen.
190If there is more than one right curly bracket on the top line,
191a number N may be used to specify the N-th bracket on the line.
192.It Ic \&(
193Like {, but applies to parentheses rather than curly brackets.
194.It Ic \&)
195Like }, but applies to parentheses rather than curly brackets.
196.It Ic \&[
197Like {, but applies to square brackets rather than curly brackets.
198.It Ic \&]
199Like }, but applies to square brackets rather than curly brackets.
200.It Ic ESC-^F
201Followed by two characters, acts like {,
202but uses the two characters as open and close brackets, respectively.
203For example, "ESC ^F < >" could be used to
204go forward to the > which matches the < in the top displayed line.
205.It Ic ESC-^B
206Followed by two characters, acts like },
207but uses the two characters as open and close brackets, respectively.
208For example, "ESC ^B < >" could be used to
209go backward to the < which matches the > in the bottom displayed line.
210.It Ic m
211Followed by any lowercase letter, marks the current position with that letter.
212.It Ic '
213(Single quote.)
214Followed by any lowercase letter, returns to the position which
215was previously marked with that letter.
216Followed by another single quote, returns to the position at
217which the last "large" movement command was executed.
218Followed by a ^ or $, jumps to the beginning or end of the file respectively.
219Marks are preserved when a new file is examined,
220so the ' command can be used to switch between input files.
221.It Ic ^X^X
222Same as single quote.
223.It Ic /pattern
224Search forward in the file for the N-th line containing the pattern.
225N defaults to 1.
226The pattern is a regular expression, as recognized by
227.Xr ed 1 .
228The search starts at the second line displayed
229(but see the -a and -j options, which change this).
230.Pp
231Certain characters are special if entered at the beginning of the pattern;
232they modify the type of search rather than become part of the pattern:
233.Bl -tag -width Ds
234.It Ic ^N | \&!
235Search for lines which do NOT match the pattern.
236.It Ic ^E | *
237Search multiple files.
238That is, if the search reaches the END of the current file
239without finding a match,
240the search continues in the next file in the command line list.
241.It Ic ^F | @
242Begin the search at the first line of the FIRST file
243in the command line list,
244regardless of what is currently displayed on the screen
245or the settings of the -a or -j options.
246.It Ic ^K
247Highlight any text which matches the pattern on the current screen,
248but don't move to the first match (KEEP current position).
249.It Ic ^R
250Don't interpret regular expression metacharacters;
251that is, do a simple textual comparison.
252.El
253.It Ic ?pattern
254Search backward in the file for the N-th line containing the pattern.
255The search starts at the line immediately before the top line displayed.
256.Pp
257Certain characters are special, as in the / command:
258.Bl -tag -width Ds
259.It Ic ^N | \&!
260Search for lines which do NOT match the pattern.
261.It Ic ^E | *
262Search multiple files.
263That is, if the search reaches the beginning of the current file
264without finding a match,
265the search continues in the previous file in the command line list.
266.It Ic ^F | @
267Begin the search at the last line of the last file
268in the command line list,
269regardless of what is currently displayed on the screen
270or the settings of the -a or -j options.
271.It Ic ^K
272As in forward searches.
273.It Ic ^R
274As in forward searches.
275.El
276.It Ic ESC-/pattern
277Same as "/*".
278.It Ic ESC-?pattern
279Same as "?*".
280.It Ic n
281Repeat previous search, for N-th line containing the last pattern.
282If the previous search was modified by ^N, the search is made for the
283N-th line NOT containing the pattern.
284If the previous search was modified by ^E, the search continues
285in the next (or previous) file if not satisfied in the current file.
286If the previous search was modified by ^R, the search is done
287without using regular expressions.
288There is no effect if the previous search was modified by ^F or ^K.
289.It Ic N
290Repeat previous search, but in the reverse direction.
291.It Ic ESC-n
292Repeat previous search, but crossing file boundaries.
293The effect is as if the previous search were modified by *.
294.It Ic ESC-N
295Repeat previous search, but in the reverse direction
296and crossing file boundaries.
297.It Ic ESC-u
298Undo search highlighting.
299Turn off highlighting of strings matching the current search pattern.
300If highlighting is already off because of a previous ESC-u command,
301turn highlighting back on.
302Any search command will also turn highlighting back on.
303(Highlighting can also be disabled by toggling the -G option;
304in that case search commands do not turn highlighting back on.)
305.It Ic :e Op Ar filename
306Examine a new file.
307If the filename is missing, the "current" file (see the :n and :p commands
308below) from the list of files in the command line is re-examined.
309A percent sign (%) in the filename is replaced by the name of the
310current file.
311A pound sign (#) is replaced by the name of the previously examined file.
312However, two consecutive percent signs are simply
313replaced with a single percent sign.
314This allows you to enter a filename that contains a percent sign
315in the name.
316Similarly, two consecutive pound signs are replaced with a single pound sign.
317The filename is inserted into the command line list of files
318so that it can be seen by subsequent :n and :p commands.
319If the filename consists of several files, they are all inserted into
320the list of files and the first one is examined.
321If the filename contains one or more spaces,
322the entire filename should be enclosed in double quotes
323(also see the -" option).
324.It Ic ^X^V | E
325Same as :e.
326Warning: some systems use ^V as a special literalization character.
327On such systems, you may not be able to use ^V.
328.It Ic :n
329Examine the next file (from the list of files given in the command line).
330If a number N is specified, the N-th next file is examined.
331.It Ic :p
332Examine the previous file in the command line list.
333If a number N is specified, the N-th previous file is examined.
334.It Ic :t
335Go to the specified tag.
336.It Ic :x
337Examine the first file in the command line list.
338If a number N is specified, the N-th file in the list is examined.
339.It Ic :d
340Remove the current file from the list of files.
341.It Ic t
342Go to the next tag, if there were more than one matches for the current tag.
343See the \-t option for more details about tags.
344.It Ic T
345Go to the previous tag, if there were more than one matches for the current tag.
346.It Ic = | ^G | :f
347Prints some information about the file being viewed, including its name
348and the line number and byte offset of the bottom line being displayed.
349If possible, it also prints the length of the file,
350the number of lines in the file
351and the percent of the file above the last displayed line.
352.It Ic \-
353Followed by one of the command line option letters (see
354.Sx OPTIONS
355below),
356this will change the setting of that option
357and print a message describing the new setting.
358If a ^P (CONTROL-P) is entered immediately after the dash,
359the setting of the option is changed but no message is printed.
360If the option letter has a numeric value (such as -b or -h),
361or a string value (such as -P or -t),
362a new value may be entered after the option letter.
363If no new value is entered, a message describing
364the current setting is printed and nothing is changed.
365.It Ic \-\-
366Like the \- command, but takes a long option name (see
367.Sx OPTIONS
368below)
369rather than a single option letter.
370You must press RETURN after typing the option name.
371A ^P immediately after the second dash suppresses printing of a
372message describing the new setting, as in the \- command.
373.It Ic \-+
374Followed by one of the command line option letters this will reset the
375option to its default setting and print a message describing the new setting.
376(The "\-+X" command does the same thing as "\-+X" on the command line.)
377This does not work for string-valued options.
378.It Ic \-\-+
379Like the \-+ command, but takes a long option name
380rather than a single option letter.
381.It Ic \-!
382Followed by one of the command line option letters, this will reset the
383option to the "opposite" of its default setting and print a message
384describing the new setting.
385This does not work for numeric or string-valued options.
386.It Ic \-\-!
387Like the \-! command, but takes a long option name
388rather than a single option letter.
389.It Ic _
390(Underscore.)
391Followed by one of the command line option letters,
392this will print a message describing the current setting of that option.
393The setting of the option is not changed.
394.It Ic __
395(Double underscore.)
396Like the _ (underscore) command, but takes a long option name
397rather than a single option letter.
398You must press RETURN after typing the option name.
399.It Ic +cmd
400Causes the specified cmd to be executed each time a new file is examined.
401For example, +G causes
402.Nm
403to initially display each file starting at the end rather than the beginning.
404.It Ic V
405Prints the version number of
406.Nm
407being run.
408.It Xo
409.Ic q No \&| Ic Q No \&|
410.Ic :q No \&| Ic :Q No \&|
411.Ic ZZ
412.Xc
413Exits
414.Nm less .
415.El
416.Pp
417The following
418four
419commands may or may not be valid, depending on your particular installation.
420.Bl -tag -width XXXX
421.It Ic v
422Invokes an editor to edit the current file being viewed.
423The editor is taken from the environment variable
424.Ev VISUAL ,
425if defined,
426or
427.Ev EDITOR
428if
429.Ev VISUAL
430is not defined,
431or defaults to "vi" if neither
432.Ev VISUAL
433nor
434.Ev EDITOR
435is defined.
436See also the discussion of LESSEDIT under the section on
437.Sx PROMPTS
438below.
439.It Ic \&! Ar shell-command
440Invokes a shell to run the shell-command given.
441A percent sign (%) in the command is replaced by the name of the current file.
442A pound sign (#) is replaced by the name of the previously examined file.
443"!!" repeats the last shell command.
444"!" with no shell command simply invokes a shell.
445The shell is taken from the environment variable
446.Ev SHELL ,
447or defaults to "sh".
448.\" On MS-DOS and OS/2 systems, the shell is the normal command processor.
449.It Ic \&| <m> Ar shell-command
450<m> represents any mark letter.
451Pipes a section of the input file to the given shell command.
452The section of the file to be piped is between the first line on
453the current screen and the position marked by the letter.
454<m> may also be ^ or $ to indicate beginning or end of file respectively.
455If <m> is . or newline, the current screen is piped.
456.It Ic s Ar filename
457Save the input to a file.
458This only works if the input is a pipe, not an ordinary file.
459.El
460.Sh OPTIONS
461Command line options are described below.
462Most options may be changed while
463.Nm
464is running, via the "\-" command.
465.Pp
466Most options may be given in one of two forms:
467either a dash followed by a single letter, or two dashes followed by a
468long option name.
469A long option name may be abbreviated as long as the abbreviation is
470unambiguous.
471For example, --quit-at-eof may be abbreviated --quit, but not
472--qui, since both --quit-at-eof and --quiet begin with --qui.
473Some long option names are in uppercase, such as --QUIT-AT-EOF, as
474distinct from --quit-at-eof.
475Such option names need only have their first letter capitalized;
476the remainder of the name may be in either case.
477For example, --Quit-at-eof is equivalent to --QUIT-AT-EOF.
478.Pp
479Options are also taken from the environment variable
480.Ev LESS
481if the command is
482.Nm less ,
483or from the environment variable
484.Ev MORE
485if the command is
486.Nm more .
487For example, to avoid typing "less -options ..." each time
488.Nm
489is invoked, you might tell
490.Xr csh 1 :
491.Pp
492.Dl setenv LESS "-options"
493.Pp
494or if you use
495.Xr sh 1 :
496.Pp
497.Dl LESS="-options"; export LESS
498.Pp
499.\" On MS-DOS, you don't need the quotes, but you should replace any
500.\" percent signs in the options string by double percent signs.
501.\" .Pp
502The environment variable is parsed before the command line,
503so command line options override the
504.Ev LESS
505environment variable.
506If an option appears in the
507.Ev LESS
508variable, it can be reset to its default value on the command line by
509beginning the command line option with "\-+".
510.Pp
511For options like -P which take a following string,
512a dollar sign ($) must be used to signal the end of the string.
513For example, to separate a prompt value from any other options
514with dollar sign between them:
515.Pp
516.Dl LESS="-Ps--More--$-C -e"
517.Bl -tag -width XXXX
518.It Fl \&? | -help
519This option displays a summary of the commands accepted by
520.Nm
521(the same as the h command).
522(Depending on how your shell interprets the question mark,
523it may be necessary to quote the question mark, thus: "-\e?".)
524.It Fl a | -search-skip-screen
525Causes searches to start after the last line displayed on the screen,
526thus skipping all lines displayed on the screen.
527By default, searches start at the second line on the screen
528(or after the last found line; see the -j option).
529.It Xo
530.Fl b Ns Ar n |
531.Fl -buffers Ns No = Ns Ar n
532.Xc
533Specifies the amount of buffer space
534.Nm
535will use for each file, in units of kilobytes (1024 bytes).
536By default 64K of buffer space is used for each file
537(unless the file is a pipe; see the -B option).
538The -b option specifies instead that n kilobytes of
539buffer space should be used for each file.
540If n is -1, buffer space is unlimited; that is,
541the entire file is read into memory.
542.It Fl B | -auto-buffers
543By default, when data is read from a pipe,
544buffers are allocated automatically as needed.
545If a large amount of data is read from the pipe, this can cause
546a large amount of memory to be allocated.
547The -B option disables this automatic allocation of buffers for pipes,
548so that only 64K (or the amount of space specified by the -b option)
549is used for the pipe.
550Warning: use of -B can result in erroneous display, since only the
551most recently viewed part of the file is kept in memory;
552any earlier data is lost.
553.It Fl c | -clear-screen
554Causes full screen repaints to be painted from the top line down.
555By default,
556full screen repaints are done by scrolling from the bottom of the screen.
557.It Fl C | -CLEAR-SCREEN
558The -C option is like -c, but the screen is cleared before it is repainted.
559.It Fl d | -dumb No (less only)
560The -d option suppresses the error message
561normally displayed if the terminal is dumb;
562that is, lacks some important capability,
563such as the ability to clear the screen or scroll backward.
564The -d option does not otherwise change the behavior of
565.Nm
566on a dumb terminal.
567This option is on by default when invoked as
568.Nm more .
569.It Fl d No (more only)
570The -d option causes the default prompt to include the
571basic directions ``[Press space to continue, 'q' to quit.]''.
572The -d option also causes the message ``[Press 'h' for instructions.]'' to be
573displayed when an invalid command is entered (normally, the bell is rung).
574This option is useful in environments where users may not be experienced
575with pagers.
576.\" .It Fl Dxcolor or --color=xcolor"
577.\" [MS-DOS only]
578.\" Sets the color of the text displayed.
579.\" x is a single character which selects the type of text whose color is
580.\" being set: n=normal, s=standout, d=bold, u=underlined, k=blink.
581.\" color is a pair of numbers separated by a period.
582.\" The first number selects the foreground color and the second selects
583.\" the background color of the text.
584.\" A single number N is the same as N.0.
585.It Fl e | -quit-at-eof
586Causes
587.Nm
588to automatically exit the second time it reaches end-of-file.
589By default, the only way to exit
590.Nm
591is via the "q" command.
592.It Fl E | -QUIT-AT-EOF
593Causes
594.Nm
595to automatically exit the first time it reaches end-of-file.
596.It Fl f | -force
597Forces non-regular files to be opened.
598(A non-regular file is a directory or a device special file.)
599Also suppresses the warning message when a binary file is opened.
600By default,
601.Nm
602will refuse to open non-regular files.
603.It Fl F | -quit-if-one-screen
604Causes
605.Nm
606to automatically exit if the entire file can be displayed on the first screen.
607.It Fl g | -hilite-search
608Normally,
609.Nm
610will highlight ALL strings which match the last search command.
611The -g option changes this behavior to highlight only the particular string
612which was found by the last search command.
613This can cause
614.Nm
615to run somewhat faster than the default.
616.It Fl G | -HILITE-SEARCH
617The -G option suppresses all highlighting of strings found by search commands.
618.It Xo
619.Fl h Ns Ar n |
620.Fl -max-back-scroll Ns No = Ns Ar n
621.Xc
622Specifies a maximum number of lines to scroll backward.
623If it is necessary to scroll backward more than n lines,
624the screen is repainted in a forward direction instead.
625(If the terminal does not have the ability to scroll backward, -h0 is implied.)
626.It Fl i | -ignore-case
627Causes searches to ignore case; that is,
628uppercase and lowercase are considered identical.
629This option is ignored if any uppercase letters appear in the search pattern;
630in other words,
631if a pattern contains uppercase letters, then that search does not ignore case.
632.It Fl I | -IGNORE-CASE
633Like -i, but searches ignore case even if the pattern contains uppercase
634letters.
635.It Xo
636.Fl j Ns Ar n |
637.Fl -jump-target Ns No = Ns Ar n
638.Xc
639Specifies a line on the screen where the "target" line is to be positioned.
640A target line is the object of a text search,
641tag search, jump to a line number,
642jump to a file percentage, or jump to a marked position.
643The screen line is specified by a number: the top line on the screen
644is 1, the next is 2, and so on.
645The number may be negative to specify a line relative to the bottom
646of the screen: the bottom line on the screen is -1, the second
647to the bottom is -2, and so on.
648If the -j option is used, searches begin at the line immediately
649after the target line.
650For example, if "-j4" is used, the target line is the
651fourth line on the screen, so searches begin at the fifth line on the screen.
652.It Fl J | -status-column
653Displays a status column at the left edge of the screen.
654The status column shows the lines that matched the current search.
655The status column is also used if the -w or -W option is in effect.
656.It Xo
657.Fl k Ns Ar filename |
658.Fl -lesskey-file Ns No = Ns Ar filename
659.Xc
660Causes
661.Nm
662to open and interpret the named file as a
663.Xr lesskey 1
664file.
665Multiple -k options may be specified.
666If the
667.Ev LESSKEY
668or
669.Ev LESSKEY_SYSTEM
670environment variable is set, or if a lesskey file is found in a standard place
671(see
672.Sx KEY BINDINGS ) ,
673it is also used as a lesskey file.
674.It Fl L | -no-lessopen
675Ignore the
676.Ev LESSOPEN
677environment variable (see the
678.Sx INPUT PREPROCESSOR
679section below).
680This option can be set from within
681.Nm less ,
682but it will apply only to files opened subsequently, not to the
683file which is currently open.
684When invoked as
685.Nm more ,
686the
687.Ev LESSOPEN
688environment variable is ignored by default.
689.It Fl m | -long-prompt
690Causes
691.Nm
692to prompt verbosely (like more), with the percent into the file.
693By default,
694.Nm
695prompts with a colon.
696.It Fl M | -LONG-PROMPT
697Causes
698.Nm
699to prompt even more verbosely than
700.Nm more .
701.It Fl n | -line-numbers
702Suppresses line numbers.
703The default (to use line numbers) may cause
704.Nm
705to run more slowly in some cases, especially with a very large input file.
706Suppressing line numbers with the -n option will avoid this problem.
707Using line numbers means: the line number will be displayed in the verbose
708prompt and in the = command, and the v command will pass the current line
709number to the editor (see also the discussion of LESSEDIT in
710.Sx PROMPTS
711below).
712.It Fl N | -LINE-NUMBERS
713Causes a line number to be displayed at the beginning of each line in the
714display.
715.It Xo
716.Fl o Ns Ar filename |
717.Fl -log-file Ns No = Ns Ar filename
718.Xc
719Causes
720.Nm
721to copy its input to the named file as it is being viewed.
722This applies only when the input file is a pipe, not an ordinary file.
723If the file already exists,
724.Nm
725will ask for confirmation before overwriting it.
726.It Xo
727.Fl O Ns Ar filename |
728.Fl -LOG-FILE Ns No = Ns Ar filename
729.Xc
730The -O option is like -o, but it will overwrite an existing
731file without asking for confirmation.
732.Pp
733If no log file has been specified,
734the -o and -O options can be used from within
735.Nm
736to specify a log file.
737Without a file name, they will simply report the name of the log file.
738The "s" command is equivalent to specifying -o from within
739.Nm less .
740.It Xo
741.Fl p Ns Ar pattern |
742.Fl -pattern Ns No = Ns Ar pattern
743.Xc
744The -p option on the command line is equivalent to specifying +/pattern;
745that is, it tells
746.Nm
747to start at the first occurrence of pattern in the file.
748.It Xo
749.Fl P Ns Ar prompt |
750.Fl -prompt Ns No = Ns Ar prompt
751.Xc
752Provides a way to tailor the three prompt styles to your own preference.
753This option would normally be put in the
754.Ev LESS
755environment variable, rather than being typed in with each
756.Nm
757command.
758Such an option must either be the last option in the
759.Ev LESS
760variable, or be terminated by a dollar sign.
761-Ps followed by a string changes the default (short) prompt to that string.
762-Pm changes the medium (-m) prompt.
763-PM changes the long (-M) prompt.
764-Ph changes the prompt for the help screen.
765-P= changes the message printed by the = command.
766-Pw changes the message printed while waiting for data (in the F command).
767All prompt strings consist of a sequence of letters and special escape
768sequences.
769See the section on
770.Sx PROMPTS
771for more details.
772.It Fl q | -quiet | -silent
773Causes moderately "quiet" operation:
774the terminal bell is not rung if an attempt is made to scroll past the end
775of the file or before the beginning of the file.
776If the terminal has a "visual bell", it is used instead.
777The bell will be rung on certain other errors,
778such as typing an invalid character.
779The default is to ring the terminal bell in all such cases.
780.It Fl Q | -QUIET | -SILENT
781Causes totally "quiet" operation: the terminal bell is never rung.
782.It Fl r | -raw-control-chars
783Causes "raw" control characters to be displayed.
784The default is to display control characters using the caret notation;
785for example, a control-A (octal 001) is displayed as "^A".
786Warning: when the -r option is used,
787.Nm
788cannot keep track of the actual appearance of the screen
789(since this depends on how the screen responds to
790each type of control character).
791Thus, various display problems may result,
792such as long lines being split in the wrong place.
793.It Fl R | -RAW-CONTROL-CHARS
794Like -r, but tries to keep track of the screen appearance where possible.
795This works only if the input consists of normal text and possibly some
796ANSI "color" escape sequences, which are sequences of the form:
797.Pp
798	ESC [ ... m
799.Pp
800where the "..." is zero or more characters other than "m".
801For the purpose of keeping track of screen appearance,
802all control characters and all ANSI color escape sequences are
803assumed to not move the cursor.
804You can make
805.Nm
806think that characters other than "m" can end ANSI color escape sequences
807by setting the environment variable
808.Ev LESSANSIENDCHARS
809to the list of characters which can end a color escape sequence.
810.It Fl s | -squeeze-blank-lines
811Causes consecutive blank lines to be squeezed into a single blank line.
812This is useful when viewing
813.Xr nroff 1
814output.
815.It Fl S | -chop-long-lines
816Causes lines longer than the screen width to be chopped rather than folded.
817That is, the portion of a long line that does not fit in
818the screen width is not shown.
819The default is to fold long lines; that is, display the remainder
820on the next line.
821.It Xo
822.Fl t Ns Ar tag |
823.Fl -tag Ns No = Ns Ar tag
824.Xc
825The -t option, followed immediately by a TAG,
826will edit the file containing that tag.
827For this to work, tag information must be available;
828for example, there may be a file in the current directory called "tags",
829which was previously built by
830.Xr ctags 1
831or an equivalent command.
832If the environment variable
833.Ev LESSGLOBALTAGS
834is set, it is taken to be the name of a command compatible with
835.Xr global ,
836and that command is executed to find the tag.
837(See http://www.gnu.org/software/global/global.html).
838The -t option may also be specified from within
839.Nm
840(using the \- command) as a way of examining a new file.
841The command ":t" is equivalent to specifying -t from within
842.Nm less .
843.It Xo
844.Fl T Ns Ar tagsfile |
845.Fl -tag-file Ns No = Ns Ar tagsfile
846.Xc
847Specifies a tags file to be used instead of "tags".
848.It Fl u | -underline-special
849Causes backspaces and carriage returns to be treated as printable characters;
850that is, they are sent to the terminal when they appear in the input.
851.It Fl U | -UNDERLINE-SPECIAL
852Causes backspaces, tabs and carriage returns to be
853treated as control characters;
854that is, they are handled as specified by the -r option.
855.Pp
856By default, if neither -u nor -U is given, backspaces which appear adjacent
857to an underscore character are treated specially:
858the underlined text is displayed
859using the terminal's hardware underlining capability.
860Also, backspaces which appear between two identical characters
861are treated specially:
862the overstruck text is printed
863using the terminal's hardware boldface capability.
864Other backspaces are deleted, along with the preceding character.
865Carriage returns immediately followed by a newline are deleted.
866Other carriage returns are handled as specified by the -r option.
867Text which is overstruck or underlined can be searched for
868if neither -u nor -U is in effect.
869.It Fl V | -version
870Displays the version number of
871.Nm less .
872.It Fl w | -hilite-unread
873Temporarily highlights the first "new" line after a forward movement
874of a full page.
875The first "new" line is the line immediately following the line previously
876at the bottom of the screen.
877Also highlights the target line after a g or p command.
878The highlight is removed at the next command which causes movement.
879The entire line is highlighted, unless the -J option is in effect,
880in which case only the status column is highlighted.
881.It Fl W | -HILITE-UNREAD
882Like -w, but temporarily highlights the first new line after any
883forward movement command larger than one line.
884.It Xo
885.Fl x Ns Ar n,... |
886.Fl -tabs Ns No = Ns Ar n,...
887.Xc
888Sets tab stops.
889If only one n is specified, tab stops are set at multiples of n.
890If multiple values separated by commas are specified, tab stops are set at
891those positions, and then continue with the same spacing as the last two.
892For example, -x9,17 will set tabs at positions 9, 17, 25, 33, etc.
893The default for n is 8.
894.It Fl X | -no-init
895Disables sending the termcap initialization and deinitialization strings
896to the terminal.
897This is sometimes desirable if the deinitialization string does
898something unnecessary, like clearing the screen.
899.It Fl -no-keypad
900Disables sending the keypad initialization and deinitialization strings
901to the terminal.
902This is sometimes useful if the keypad strings make the numeric
903keypad behave in an undesirable manner.
904.It Xo
905.Fl y Ns Ar n |
906.Fl -max-forw-scroll Ns No = Ns Ar n
907.Xc
908Specifies a maximum number of lines to scroll forward.
909If it is necessary to scroll forward more than n lines,
910the screen is repainted instead.
911The -c or -C option may be used to repaint from the top of
912the screen if desired.
913By default, any forward movement causes scrolling.
914.It Xo
915.Fl Oo Cm z Oc Ns Ar n |
916.Fl -window Ns No = Ns Ar n
917.Xc
918Changes the default scrolling window size to n lines.
919The default is one screenful.
920The z and w commands can also be used to change the window size.
921The "z" may be omitted for compatibility with
922.Nm more .
923If the number
924.Ar n
925is negative, it indicates
926.Ar n
927lines less than the current screen size.
928For example, if the screen is 24 lines, -z-4 sets the
929scrolling window to 20 lines.
930If the screen is resized to 40 lines,
931the scrolling window automatically changes to 36 lines.
932.It Xo
933.Ar -cc |
934.Fl -quotes Ns No = Ns Ar cc
935.Xc
936Changes the filename quoting character.
937This may be necessary if you are trying to name a file
938which contains both spaces and quote characters.
939Followed by a single character, this changes the quote character to that
940character.
941Filenames containing a space should then be surrounded by that character
942rather than by double quotes.
943Followed by two characters, changes the open quote to the first character,
944and the close quote to the second character.
945Filenames containing a space should then be preceded by the open quote
946character and followed by the close quote character.
947Note that even after the quote characters are changed, this option
948remains -" (a dash followed by a double quote).
949.It Fl ~ | -tilde
950Normally lines after end of file are displayed as a single tilde (~).
951This option causes lines after end of file to be displayed as blank lines.
952.It Fl # | -shift
953Specifies the default number of positions to scroll horizontally
954in the RIGHTARROW and LEFTARROW commands.
955If the number specified is zero, it sets the default number of
956positions to one half of the screen width.
957.It Fl -
958A command line argument of "--" marks the end of option arguments.
959Any arguments following this are interpreted as filenames.
960This can be useful when viewing a file whose name begins with a "-" or "+".
961.It Cm +
962If a command line option begins with +,
963the remainder of that option is taken to be an initial command to
964.Nm less .
965For example, +G tells
966.Nm
967to start at the end of the file rather than the beginning,
968and +/xyz tells it to start at the first occurrence of "xyz" in the file.
969As a special case, +<number> acts like +<number>g;
970that is, it starts the display at the specified line number
971(however, see the caveat under the "g" command above).
972If the option starts with ++, the initial command applies to
973every file being viewed, not just the first one.
974The + command described previously
975may also be used to set (or change) an initial command for every file.
976.El
977.Sh LINE EDITING
978When entering command line at the bottom of the screen
979(for example, a filename for the :e command,
980or the pattern for a search command),
981certain keys can be used to manipulate the command line.
982Most commands have an alternate form in [ brackets ] which can be used if
983a key does not exist on a particular keyboard.
984.\" (The bracketed forms do not work in the MS-DOS version.)
985Any of these special keys may be entered literally by preceding
986it with the "literal" character, either ^V or ^A.
987A backslash itself may also be entered literally by entering two backslashes.
988.Bl -tag -width Ds
989.It LEFTARROW [ ESC-h ]
990Move the cursor one space to the left.
991.It RIGHTARROW [ ESC-l ]
992Move the cursor one space to the right.
993.It ^LEFTARROW [ ESC-b or ESC-LEFTARROW ]
994(That is, CONTROL and LEFTARROW simultaneously.)
995Move the cursor one word to the left.
996.It ^RIGHTARROW [ ESC-w or ESC-RIGHTARROW ]
997(That is, CONTROL and RIGHTARROW simultaneously.)
998Move the cursor one word to the right.
999.It HOME [ ESC-0 ]
1000Move the cursor to the beginning of the line.
1001.It END [ ESC-$ ]
1002Move the cursor to the end of the line.
1003.It BACKSPACE
1004Delete the character to the left of the cursor,
1005or cancel the command if the command line is empty.
1006.It DELETE or [ ESC-x ]
1007Delete the character under the cursor.
1008.It ^BACKSPACE [ ESC-BACKSPACE ]
1009(That is, CONTROL and BACKSPACE simultaneously.)
1010Delete the word to the left of the cursor.
1011.It ^DELETE [ ESC-X or ESC-DELETE ]
1012(That is, CONTROL and DELETE simultaneously.)
1013Delete the word under the cursor.
1014.It UPARROW [ ESC-k ]
1015Retrieve the previous command line.
1016.It DOWNARROW [ ESC-j ]
1017Retrieve the next command line.
1018.It TAB
1019Complete the partial filename to the left of the cursor.
1020If it matches more than one filename, the first match
1021is entered into the command line.
1022Repeated TABs will cycle through the other matching filenames.
1023If the completed filename is a directory, a "/" is appended to the filename.
1024.\" (On MS-DOS systems, a "\e" is appended.)
1025The environment variable
1026.Ev LESSSEPARATOR
1027can be used to specify a different character to append to a directory name.
1028.It BACKTAB [ ESC-TAB ]
1029Like TAB, but cycles in the reverse direction through the matching filenames.
1030.It ^L
1031Complete the partial filename to the left of the cursor.
1032If it matches more than one filename, all matches are entered into
1033the command line (if they fit).
1034.\" .It ^U (Unix and OS/2) or ESC (MS-DOS)
1035.It ^U
1036Delete the entire command line,
1037or cancel the command if the command line is empty.
1038If you have changed your line-kill character to something
1039other than ^U, that character is used instead of ^U.
1040.El
1041.Sh KEY BINDINGS
1042You may define your own
1043.Nm
1044commands by using the program
1045.Xr lesskey 1
1046to create a lesskey file.
1047This file specifies a set of command keys and an action
1048associated with each key.
1049You may also use lesskey
1050to change the line-editing keys (see
1051.Sx LINE EDITING ) ,
1052and to set environment variables.
1053If the environment variable
1054.Ev LESSKEY
1055is set,
1056.Nm
1057uses that as the name of the lesskey file.
1058Otherwise,
1059.Nm
1060looks for a lesskey file called "$HOME/.less".
1061.\" On MS-DOS and Windows systems,
1062.\" .I less
1063.\" looks for a lesskey file called "$HOME/_less", and if it is not found there,
1064.\" then looks for a lesskey file called "_less" in any directory specified
1065.\" in the PATH environment variable.
1066.\" On OS/2 systems,
1067.\" .I less
1068.\" looks for a lesskey file called "$HOME/less.ini", and if it is not found,
1069.\" then looks for a lesskey file called "less.ini" in any directory specified
1070.\" in the INIT environment variable, and if it not found there,
1071.\" then looks for a lesskey file called "less.ini" in any directory specified
1072.\" in the PATH environment variable.
1073See the
1074.Xr lesskey 1
1075manual page for more details.
1076.Pp
1077A system-wide lesskey file may also be set up to provide key bindings.
1078If a key is defined in both a local lesskey file and in the
1079system-wide file, key bindings in the local file take precedence over
1080those in the system-wide file.
1081If the environment variable
1082.Ev LESSKEY_SYSTEM
1083is set,
1084.Nm
1085uses that as the name of the system-wide lesskey file.
1086Otherwise,
1087.Nm
1088looks in a standard place for the system-wide lesskey file:
1089On
1090.Ox ,
1091the system-wide lesskey file is
1092.Pa /etc/sysless .
1093.\" On Unix systems, the system-wide lesskey file is /usr/local/etc/sysless.
1094.\" (However, if
1095.\" .Nm less
1096.\" was built with a different sysconf directory than /usr/local/etc,
1097.\" that directory is where the sysless file is found.)
1098.\" On MS-DOS and Windows systems, the system-wide lesskey file is c:\e_sysless.
1099.\" On OS/2 systems, the system-wide lesskey file is c:\esysless.ini.
1100.Sh INPUT PREPROCESSOR
1101You may define an "input preprocessor" for
1102.Nm less .
1103Before
1104.Nm less
1105opens a file, it first gives your input preprocessor a chance to modify the
1106way the contents of the file are displayed.
1107An input preprocessor is simply an executable program (or shell script),
1108which writes the contents of the file to a different file,
1109called the replacement file.
1110The contents of the replacement file are then displayed
1111in place of the contents of the original file.
1112However, it will appear to the user as if the original file is opened;
1113that is,
1114.Nm less
1115will display the original filename as the name of the current file.
1116.Pp
1117An input preprocessor receives one command line argument, the original filename,
1118as entered by the user.
1119It should create the replacement file, and when finished
1120print the name of the replacement file to its standard output.
1121If the input preprocessor does not output a replacement filename,
1122.Nm
1123uses the original file, as normal.
1124The input preprocessor is not called when viewing standard input.
1125To set up an input preprocessor, set the
1126.Ev LESSOPEN
1127environment variable to a command line which will invoke your
1128input preprocessor.
1129This command line should include one occurrence of the string "%s",
1130which will be replaced by the filename
1131when the input preprocessor command is invoked.
1132.Pp
1133When
1134.Nm
1135closes a file opened in such a way, it will call another program,
1136called the input postprocessor,
1137which may perform any desired clean-up action (such as deleting the
1138replacement file created by
1139.Ev LESSOPEN ) .
1140This program receives two command line arguments, the original filename
1141as entered by the user, and the name of the replacement file.
1142To set up an input postprocessor, set the
1143.Ev LESSCLOSE
1144environment variable to a command line which will invoke your
1145input postprocessor.
1146It may include two occurrences of the string "%s";
1147the first is replaced with the original name of the file and the second
1148with the name of the replacement file, which was output by
1149.Ev LESSOPEN .
1150.Pp
1151For example, these two scripts will allow you
1152to keep files in compressed format, but still let
1153.Nm
1154view them directly:
1155.Pp
1156lessopen.sh:
1157.Bd -literal -offset indent
1158#! /bin/sh
1159case "$1" in
1160*.Z)	uncompress -c $1  >/tmp/less.$$  2>/dev/null
1161	if [ -s /tmp/less.$$ ]; then
1162		echo /tmp/less.$$
1163	else
1164		rm -f /tmp/less.$$
1165	fi
1166	;;
1167esac
1168.Ed
1169.Pp
1170lessclose.sh:
1171.Bd -literal -offset indent
1172#! /bin/sh
1173rm $2
1174.Ed
1175.Pp
1176To use these scripts, put them both where they can be executed and
1177set LESSOPEN="lessopen.sh\ %s", and LESSCLOSE="lessclose.sh\ %s\ %s".
1178More complex LESSOPEN and LESSCLOSE scripts may be written
1179to accept other types of compressed files, and so on.
1180.Pp
1181It is also possible to set up an input preprocessor to
1182pipe the file data directly to
1183.Nm less ,
1184rather than putting the data into a replacement file.
1185This avoids the need to decompress the entire file before starting to view it.
1186An input preprocessor that works this way is called an input pipe.
1187An input pipe, instead of writing the name of a replacement file on
1188its standard output,
1189writes the entire contents of the replacement file on its standard output.
1190If the input pipe does not write any characters on its standard output,
1191then there is no replacement file and
1192.Nm
1193uses the original file, as normal.
1194To use an input pipe, make the first character in the
1195.Ev LESSOPEN
1196environment variable a vertical bar (|) to signify that the
1197input preprocessor is an input pipe.
1198.Pp
1199For example, this script will work like the previous example scripts:
1200.Pp
1201lesspipe.sh:
1202.Bd -literal -offset indent
1203#! /bin/sh
1204case "$1" in
1205*.Z)	uncompress -c $1  2>/dev/null
1206	;;
1207esac
1208.Ed
1209.Pp
1210To use this script, put it where it can be executed and set
1211LESSOPEN="|lesspipe.sh %s".
1212When an input pipe is used, a LESSCLOSE postprocessor can be used,
1213but it is usually not necessary since there is no replacement file to clean up.
1214In this case, the replacement file name passed to the LESSCLOSE
1215postprocessor is "-".
1216.Sh NATIONAL CHARACTER SETS
1217There are three types of characters in the input file:
1218.Bl -tag -width "control characters"
1219.It normal characters
1220Can be displayed directly to the screen.
1221.It control characters
1222Should not be displayed directly, but are expected to be found
1223in ordinary text files (such as backspace and tab).
1224.It binary characters
1225Should not be displayed directly and are not expected to be found
1226in text files.
1227.El
1228.Pp
1229A "character set" is simply a description of which characters are to
1230be considered normal, control, and binary.
1231The
1232.Ev LESSCHARSET
1233environment variable may be used to select a character set.
1234Possible values for
1235.Ev LESSCHARSET
1236are:
1237.Bl -tag -width "IBM-1047"
1238.It ascii
1239BS, TAB, NL, CR, and formfeed are control characters,
1240all chars with values between 32 and 126 are normal,
1241and all others are binary.
1242.It iso8859
1243Selects an ISO 8859 character set.
1244This is the same as ASCII, except characters between 160 and 255 are
1245treated as normal characters.
1246.It latin1
1247Same as iso8859.
1248.It latin9
1249Same as iso8859.
1250.It dos
1251Selects a character set appropriate for MS-DOS.
1252.It ebcdic
1253Selects an EBCDIC character set.
1254.It IBM-1047
1255Selects an EBCDIC character set used by OS/390 Unix Services.
1256This is the EBCDIC analogue of latin1.
1257You get similar results by setting either LESSCHARSET=IBM-1047 or
1258LC_CTYPE=en_US in your environment.
1259.It koi8-r
1260Selects a Russian character set.
1261.It next
1262Selects a character set appropriate for NeXT computers.
1263.It utf-8
1264Selects the UTF-8 encoding of the ISO 10646 character set.
1265.El
1266.Pp
1267In special cases, it may be desired to tailor
1268.Nm
1269to use a character set other than the ones definable by LESSCHARSET.
1270In this case, the environment variable
1271.Ev LESSCHARDEF
1272can be used to define a character set.
1273It should be set to a string where each character in the string represents
1274one character in the character set.
1275The character "." is used for a normal character, "c" for control,
1276and "b" for binary.
1277A decimal number may be used for repetition.
1278For example, "bccc4b." would mean character 0 is binary,
12791, 2 and 3 are control, 4, 5, 6 and 7 are binary, and 8 is normal.
1280All characters after the last are taken to be the same as the last,
1281so characters 9 through 255 would be normal.
1282(This is an example, and does not necessarily
1283represent any real character set.)
1284.Pp
1285This table shows the value of LESSCHARDEF which is equivalent
1286to each of the possible values for LESSCHARSET:
1287.Bd -literal -offset indent
1288ascii		8bcccbcc18b95.b
1289dos		8bcccbcc12bc5b95.b.
1290ebcdic		5bc6bcc7bcc41b.9b7.9b5.b..8b6.10b6.b9.7b
1291		9.8b8.17b3.3b9.7b9.8b8.6b10.b.b.b.
1292IBM-1047	4cbcbc3b9cbccbccbb4c6bcc5b3cbbc4bc4bccbc
1293		191.b
1294iso8859		8bcccbcc18b95.33b.
1295koi8-r		8bcccbcc18b95.b128.
1296latin1		8bcccbcc18b95.33b.
1297next		8bcccbcc18b95.bb125.bb
1298.Ed
1299.Pp
1300If neither LESSCHARSET nor LESSCHARDEF is set,
1301but the string "UTF-8" is found in the
1302.Ev LC_ALL , LC_TYPE
1303or
1304.Ev LANG
1305environment variables, then the default character set is utf-8.
1306.Pp
1307If that string is not found, but your system supports the
1308setlocale interface,
1309.Nm
1310will use setlocale to determine the character set.
1311setlocale is controlled by setting the
1312.Ev LANG
1313or
1314.Ev LC_CTYPE
1315environment variables.
1316.Pp
1317Finally, if the
1318setlocale interface is also not available, the default character set is latin1.
1319.Pp
1320Control and binary characters are displayed in standout (reverse video).
1321Each such character is displayed in caret notation if possible
1322(e.g. ^A for control-A).
1323Caret notation is used only if inverting the 0100 bit results in a
1324normal printable character.
1325Otherwise, the character is displayed as a hex number in angle brackets.
1326This format can be changed by setting the
1327.Ev LESSBINFMT
1328environment variable.
1329LESSBINFMT may begin with a "*" and one character to select
1330the display attribute:
1331"*k" is blinking, "*d" is bold, "*u" is underlined, "*s" is standout,
1332and "*n" is normal.
1333If LESSBINFMT does not begin with a "*", normal attribute is assumed.
1334The remainder of LESSBINFMT is a string which may include one
1335printf-style escape sequence (a % followed by x, X, o, d, etc.).
1336For example, if LESSBINFMT is "*u[%x]", binary characters
1337are displayed in underlined hexadecimal surrounded by brackets.
1338The default if no LESSBINFMT is specified is "*s<%X>".
1339.Sh PROMPTS
1340The -P option allows you to tailor the prompt to your preference.
1341The string given to the -P option replaces the specified prompt string.
1342Certain characters in the string are interpreted specially.
1343The prompt mechanism is rather complicated to provide flexibility,
1344but the ordinary user need not understand the details of constructing
1345personalized prompt strings.
1346.Pp
1347A percent sign followed by a single character is expanded
1348according to what the following character is:
1349.Bl -tag -width Ds
1350.It %b Ns Ar X
1351Replaced by the byte offset into the current input file.
1352The b is followed by a single character (shown as
1353.Ar X
1354above) which specifies the line whose byte offset is to be used.
1355If the character is a "t", the byte offset of the top line in the
1356display is used,
1357an "m" means use the middle line,
1358a "b" means use the bottom line,
1359a "B" means use the line just after the bottom line,
1360and a "j" means use the "target" line, as specified by the -j option.
1361.It \&%B
1362Replaced by the size of the current input file.
1363.It %c
1364Replaced by the column number of the text appearing in the first
1365column of the screen.
1366.It %d Ns Ar X
1367Replaced by the page number of a line in the input file.
1368The line to be used is determined by the
1369.Ar X ,
1370as with the %b option.
1371.It \&%D
1372Replaced by the number of pages in the input file,
1373or equivalently, the page number of the last line in the input file.
1374.It %E
1375Replaced by the name of the editor (from the
1376.Ev VISUAL
1377environment variable, or the
1378.Ev EDITOR
1379environment variable if
1380.Ev VISUAL
1381is not defined).
1382See the discussion of the LESSEDIT feature below.
1383.It %f
1384Replaced by the name of the current input file.
1385.It %i
1386Replaced by the index of the current file in the list of
1387input files.
1388.It %l Ns Ar X
1389Replaced by the line number of a line in the input file.
1390The line to be used is determined by the
1391.Ar X ,
1392as with the %b option.
1393.It %L
1394Replaced by the line number of the last line in the input file.
1395.It %m
1396Replaced by the total number of input files.
1397.It %p Ns Ar X
1398Replaced by the percent into the current input file, based on byte offsets.
1399The line used is determined by the
1400.Ar X ,
1401as with the %b option.
1402.It \&%P Ns Ar X
1403Replaced by the percent into the current input file, based on line numbers.
1404The line used is determined by the
1405.Ar X ,
1406as with the %b option.
1407.It %s
1408Same as %B.
1409.It %t
1410Causes any trailing spaces to be removed.
1411Usually used at the end of the string, but may appear anywhere.
1412.It %x
1413Replaced by the name of the next input file in the list.
1414.El
1415.Pp
1416If any item is unknown (for example, the file size if input is a pipe),
1417a question mark is printed instead.
1418.Pp
1419The format of the prompt string can be changed depending on certain conditions.
1420A question mark followed by a single character acts like an "IF":
1421depending on the following character, a condition is evaluated.
1422If the condition is true, any characters following the question mark
1423and condition character, up to a period, are included in the prompt.
1424If the condition is false, such characters are not included.
1425A colon appearing between the question mark and the
1426period can be used to establish an "ELSE": any characters between
1427the colon and the period are included in the string, if and only if
1428the IF condition is false.
1429Condition characters (which follow a question mark) may be:
1430.Bl -tag -width Ds
1431.It ?a
1432True if any characters have been included in the prompt so far.
1433.It ?b Ns Ar X
1434True if the byte offset of the specified line is known.
1435.It ?B
1436True if the size of the current input file is known.
1437.It ?c
1438True if the text is horizontally shifted (%c is not zero).
1439.It ?d Ns Ar X
1440True if the page number of the specified line is known.
1441.It ?e
1442True if at end-of-file.
1443.It ?f
1444True if there is an input filename
1445(that is, if input is not a pipe).
1446.It ?l Ns Ar X
1447True if the line number of the specified line is known.
1448.It ?L
1449True if the line number of the last line in the file is known.
1450.It ?m
1451True if there is more than one input file.
1452.It ?n
1453True if this is the first prompt in a new input file.
1454.It ?p Ns Ar X
1455True if the percent into the current input file, based on byte offsets,
1456of the specified line is known.
1457.It ?P Ns Ar X
1458True if the percent into the current input file, based on line numbers,
1459of the specified line is known.
1460.It ?s
1461Same as "?B".
1462.It ?x
1463True if there is a next input file
1464(that is, if the current input file is not the last one).
1465.El
1466.Pp
1467Any characters other than the special ones
1468(question mark, colon, period, percent, and backslash)
1469become literally part of the prompt.
1470Any of the special characters may be included in the prompt literally
1471by preceding it with a backslash.
1472.Pp
1473Some examples:
1474.Pp
1475.Dl ?f%f:Standard input.
1476.Pp
1477This prompt prints the filename, if known;
1478otherwise the string "Standard input".
1479.Pp
1480.Dl ?f%f .?ltLine %lt:?pt%pt\e%:?btByte %bt:-...
1481.Pp
1482This prompt would print the filename, if known.
1483The filename is followed by the line number, if known,
1484otherwise the percent if known, otherwise the byte offset if known.
1485Otherwise, a dash is printed.
1486Notice how each question mark has a matching period,
1487and how the % after the %pt
1488is included literally by escaping it with a backslash.
1489.Pp
1490.Dl ?n?f%f\ .?m(file\ %i\ of\ %m)\ ..?e(END)\ ?x-\ Next\e:\ %x..%t
1491.Pp
1492This prints the filename if this is the first prompt in a file,
1493followed by the "file N of N" message if there is more
1494than one input file.
1495Then, if we are at end-of-file, the string "(END)" is printed
1496followed by the name of the next file, if there is one.
1497Finally, any trailing spaces are truncated.
1498This is the default prompt.
1499For reference, here are the defaults for
1500the other two prompts (-m and -M respectively).
1501Each is broken into two lines here for readability only.
1502.Bd -literal -offset indent
1503?n?f%f\ .?m(file\ %i\ of\ %m)\ ..?e(END)\ ?x-\ Next\e:\ %x.:
1504	?pB%pB\e%:byte\ %bB?s/%s...%t
1505
1506?f%f\ .?n?m(file\ %i\ of\ %m)\ ..?ltlines\ %lt-%lb?L/%L.\ :
1507	byte\ %bB?s/%s.\ .?e(END)\ ?x-\ Next\e:\ %x.:?pB%pB\e%..%t
1508.Ed
1509.Pp
1510And here is the default message produced by the = command:
1511.Bd -literal -offset indent
1512?f%f\ .?m(file\ %i\ of\ %m)\ .?ltlines\ %lt-%lb?L/%L.\ .
1513	byte\ %bB?s/%s.\ ?e(END)\ :?pB%pB\e%..%t
1514.Ed
1515.Pp
1516The prompt expansion features are also used for another purpose:
1517if an environment variable
1518.Ev LESSEDIT
1519is defined, it is used as the command to be executed when the v command
1520is invoked.
1521The LESSEDIT string is expanded in the same way as the prompt strings.
1522The default value for LESSEDIT is:
1523.Pp
1524.Dl %E\ ?lm+%lm.\ %f
1525.Pp
1526Note that this expands to the editor name, followed by a + and the
1527line number, followed by the file name.
1528If your editor does not accept the "+linenumber" syntax, or has other
1529differences in invocation syntax, the
1530.Ev LESSEDIT
1531variable can be changed to modify this default.
1532.Sh SECURITY
1533When the environment variable
1534.Ev LESSSECURE
1535is set to 1,
1536.Nm
1537runs in a "secure" mode.
1538This means these features are disabled:
1539.Bl -tag -width Ds
1540.It \&!
1541The shell command.
1542.It |
1543The pipe command.
1544.It :e
1545The examine command.
1546.It v
1547The editing command.
1548.It s -o
1549Log files.
1550.It -k
1551Use of lesskey files.
1552.It -t
1553Use of tags files.
1554.It " "
1555Metacharacters in filenames, such as "*".
1556.It " "
1557Filename completion (TAB, ^L).
1558.El
1559.Pp
1560Less can also be compiled to be permanently in "secure" mode.
1561.Sh ENVIRONMENT
1562Environment variables may be specified either in the system environment
1563as usual, or in a
1564.Xr lesskey 1
1565file.
1566If environment variables are defined in more than one place,
1567variables defined in a local lesskey file take precedence over
1568variables defined in the system environment, which take precedence
1569over variables defined in the system-wide lesskey file.
1570.Bl -tag -width Ds
1571.It Ev COLUMNS
1572Sets the number of columns on the screen.
1573Takes precedence over the number of columns specified by the TERM variable.
1574(But if you have a windowing system which supports TIOCGWINSZ or WIOCGETD,
1575the window system's idea of the screen size takes precedence over the
1576LINES and COLUMNS environment variables.)
1577.It Ev EDITOR
1578The name of the editor (used for the v command).
1579.It Ev HOME
1580Name of the user's home directory
1581(used to find a lesskey file).
1582.\" .It Ev "HOMEDRIVE, HOMEPATH"
1583.\" Concatenation of the HOMEDRIVE and HOMEPATH environment variables is
1584.\" the name of the user's home directory if the HOME variable is not set
1585.\" (only in the Windows version).
1586.\" .It Ev INIT
1587.\" Name of the user's init directory
1588.\" (used to find a lesskey file on OS/2 systems).
1589.It Ev LANG
1590Language for determining the character set.
1591.It Ev LC_CTYPE
1592Language for determining the character set.
1593.It Ev LESS
1594Options which are passed to
1595.Nm
1596automatically.
1597.It Ev LESSANSIENDCHARS
1598Characters which are assumed to end an ANSI color escape sequence
1599(default "m").
1600.It Ev LESSBINFMT
1601Format for displaying non-printable, non-control characters.
1602.It Ev LESSCHARDEF
1603Defines a character set.
1604.It Ev LESSCHARSET
1605Selects a predefined character set.
1606.It Ev LESSCLOSE
1607Command line to invoke the (optional) input-postprocessor.
1608.\" .It Ev LESSECHO
1609.\" Name of the lessecho program (default "lessecho").
1610.\" The lessecho program is needed to expand metacharacters, such as * and ?,
1611.\" in filenames on Unix systems.
1612.It Ev LESSEDIT
1613Editor prototype string (used for the v command).
1614See discussion under
1615.Sx PROMPTS .
1616.It Ev LESSGLOBALTAGS
1617Name of the command used by the -t option to find global tags.
1618Normally should be set to "global" if your system has the global command.
1619If not set, global tags are not used.
1620.It Ev LESSKEY
1621Name of the default lesskey(1) file.
1622.It Ev LESSKEY_SYSTEM
1623Name of the default system-wide lesskey(1) file.
1624.It Ev LESSMETACHARS
1625List of characters which are considered "metacharacters" by the shell.
1626.It Ev LESSMETAESCAPE
1627Prefix which
1628.Nm
1629will add before each metacharacter in a command sent to the shell.
1630If LESSMETAESCAPE is an empty string, commands containing
1631metacharacters will not be passed to the shell.
1632.It Ev LESSOPEN
1633Command line to invoke the (optional) input-preprocessor.
1634.It Ev LESSSECURE
1635Runs less in "secure" mode.
1636See discussion under
1637.Sx SECURITY .
1638.It Ev LESSSEPARATOR
1639String to be appended to a directory name in filename completion.
1640.It Ev LINES
1641Sets the number of lines on the screen.
1642Takes precedence over the number of lines specified by the TERM variable.
1643(But if you have a windowing system which supports TIOCGWINSZ or WIOCGETD,
1644the window system's idea of the screen size takes precedence over the
1645LINES and COLUMNS environment variables.)
1646.\" .It Ev PATH
1647.\" User's search path (used to find a lesskey file
1648.\" on MS-DOS and OS/2 systems).
1649.It Ev SHELL
1650The shell used to execute the ! command, as well as to expand filenames.
1651.It Ev TERM
1652The type of terminal on which
1653.Nm
1654is being run.
1655.It Ev VISUAL
1656The name of the editor (used for the v command).
1657.El
1658.Sh SEE ALSO
1659.Xr lesskey 1
1660.Sh AUTHORS
1661.An Mark Nudelman Aq markn@greenwoodsoftware.com
1662.Pp
1663Send bug reports or comments to the above address or to
1664.Aq bug\-less@gnu.org .
1665.Pp
1666For more information, see the less homepage at
1667.Pa http://www.greenwoodsoftware.com/less .
1668.Sh CAVEATS
1669The = command and prompts (unless changed by -P)
1670report the line numbers of the lines at the top and bottom of the screen,
1671but the byte and percent of the line after the one at the bottom of the screen.
1672.Pp
1673If the :e command is used to name more than one file,
1674and one of the named files has been viewed previously,
1675the new files may be entered into the list in an unexpected order.
1676.Pp
1677On certain older terminals (the so-called "magic cookie" terminals),
1678search highlighting will cause an erroneous display.
1679On such terminals, search highlighting is disabled by default
1680to avoid possible problems.
1681.Pp
1682In certain cases, when search highlighting is enabled and
1683a search pattern begins with a ^,
1684more text than the matching string may be highlighted.
1685(This problem does not occur when
1686.Nm
1687is compiled to use the POSIX regular expression package.)
1688.Pp
1689When viewing text containing ANSI color escape sequences using the -R option,
1690searching will not find text containing an embedded escape sequence.
1691Also, search highlighting may change the color of some of the text
1692which follows the highlighted text.
1693.Pp
1694On some systems, setlocale claims that ASCII characters 0 through 31 are
1695control characters rather than binary characters.
1696This causes
1697.Nm
1698to treat some binary files as ordinary, non-binary files.
1699To workaround this problem, set the environment variable
1700.Ev LESSCHARSET
1701to "ascii" (or whatever character set is appropriate).
1702.Pp
1703See
1704.Pa http://www.greenwoodsoftware.com/less
1705for the latest list of known bugs in this version of
1706.Nm less .
1707.Sh COPYRIGHT
1708Copyright (C) 2002  Mark Nudelman
1709.Pp
1710Redistribution and use in source and binary forms, with or without
1711modification, are permitted provided that the following conditions
1712are met:
1713.Bl -enum -compact
1714.It
1715Redistributions of source code must retain the above copyright
1716notice, this list of conditions and the following disclaimer.
1717.It
1718Redistributions in binary form must reproduce the above copyright
1719notice in the documentation and/or other materials provided with
1720the distribution.
1721.El
1722.Pp
1723THIS SOFTWARE IS PROVIDED BY THE AUTHOR
1724.Dq AS IS
1725AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1726IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1727PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE
1728FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1729CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
1730OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
1731BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
1732WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
1733OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
1734IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1735