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