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