lesskey - Man Page

customize key bindings for less

SYNOPSIS (deprecated)

lesskey [-o output] [--] [input]
lesskey [--output=output] [--] [input]
lesskey -V
lesskey --version

Scope

This document describes the format of the lesskey source file, which is used by less version 582 and later. In previous versions of less, a separate program called lesskey was used to compile the lesskey source file into a format understood by less. This compilation step is no longer required and the lesskey program is therefore deprecated, although the file format remains supported by less itself.

Description

A lesskey file specifies a set of key bindings and environment variables to be used by subsequent invocations of less.

File Format

The input file consists of one or more sections. Each section starts with a line that identifies the type of section. Possible sections are:

#command

Customizes command key bindings.

#line-edit

Customizes line-editing key bindings.

#env

Defines environment variables.

Blank lines and lines which start with a hash mark (#) are ignored, except as noted below.

Command Section

The command section begins with the line

#command

If the command section is the first section in the file, this line may be omitted. The command section consists of lines of the form:

string <whitespace> action [extra-string] <newline>

Whitespace is any sequence of one or more spaces and/or tabs. The string is the command key(s) which invoke the action. The string may be a single command key, or a sequence of up to 15 keys. The action is the name of the less action, from the list below. The characters in the string may appear literally, or be prefixed by a caret to indicate a control key. A backslash followed by one to three octal digits may be used to specify a character by its octal value. A backslash followed by certain characters specifies input characters as follows:

\bBACKSPACE(0x08)
\eESCAPE(0x1B)
\nNEWLINE(0x0A)
\rRETURN(0x0D)
\tTAB(0x09)

\k followed by a single character represents the char(s) produced when one of these keys is pressed:

\kbBACKSPACE (the BACKSPACE key)
\kBctrl-BACKSPACE
\kdDOWN ARROW
\kDPAGE DOWN
\keEND
\khHOME
\kiINSERT
\klLEFT ARROW
\kLctrl-LEFT ARROW
\krRIGHT ARROW
\kRctrl-RIGHT ARROW
\ktBACKTAB
\kuUP ARROW
\kUPAGE UP
\kxDELETE
\kXctrl-DELETE
\k1F1

A backslash followed by any other character indicates that character is to be taken literally. Characters which must be preceded by backslash include caret, space, tab, hash mark and the backslash itself.

An action may be followed by an "extra" string. When such a command is entered while running less, the action is performed, and then the extra string is parsed, just as if it were typed in to less. This feature can be used in certain cases to extend the functionality of a command. For example, see the "{" and ":t" commands in the example below. The extra string has a special meaning for the "quit" action: when less quits, the ASCII value of the first character of the extra string  is used as its exit status.

Example

The following input file describes the set of default command keys used by less. Documentation on each command can be found in the less man page, under the key sequence which invokes the command.

#command
\rforw-line
\nforw-line
eforw-line
jforw-line
\kdforw-line
^Eforw-line
^Nforw-line
kback-line
yback-line
^Yback-line
^Kback-line
^Pback-line
Jforw-line-force
Kback-line-force
Yback-line-force
dforw-scroll
^Dforw-scroll
uback-scroll
^Uback-scroll
\40forw-screen
fforw-screen
^Fforw-screen
^Vforw-screen
\kDforw-screen
bback-screen
^Bback-screen
\evback-screen
\kUback-screen
zforw-window
wback-window
\e\40forw-screen-force
Fforw-forever
\eFforw-until-hilite
Rrepaint-flush
rrepaint
^Rrepaint
^Lrepaint
\euundo-hilite
\eUclear-search
ggoto-line
\khgoto-line
<goto-line
\e<goto-line
ppercent
%percent
\e(left-scroll
\e)right-scroll
\klleft-scroll
\krright-scroll
\e{no-scroll
\e}end-scroll
{forw-bracket {}
}back-bracket {}
(forw-bracket ()
)back-bracket ()
[forw-bracket []
]back-bracket []
\e^Fforw-bracket
\e^Bback-bracket
Ggoto-end
\e>goto-end
>goto-end
\kegoto-end
\eGgoto-end-buffered
=status
^Gstatus
:fstatus
/forw-search
?back-search
\e/forw-search *
\e?back-search *
nrepeat-search
\enrepeat-search-all
Nreverse-search
\eNreverse-search-all
^O^Nosc8-forw-search
^Onosc8-forw-search
^O^Posc8-back-search
^Oposc8-back-search
^O^Oosc8-open
&filter
mset-mark
Mset-mark-bottom
\emclear-mark
'goto-mark
^X^Xgoto-mark
Eexamine
:eexamine
^X^Vexamine
:nnext-file
:pprev-file
tnext-tag
Tprev-tag
:xindex-file
:dremove-file
-toggle-option
:ttoggle-option t
stoggle-option o
## Use a long option name by starting the
## extra string with ONE dash; eg:
##   s toggle-option -log-file\n
_display-option
|pipe
vvisual
!shell
#pshell
+firstcmd
Hhelp
hhelp
Vversion
0digit
1digit
2digit
3digit
4digit
5digit
6digit
7digit
8digit
9digit
qquit
Qquit
:qquit
:Qquit
ZZquit

Precedence

Commands specified by lesskey take precedence over the default commands. A default command key may be disabled by including it in the input file with the action "invalid". Alternatively, a key may be defined to do nothing by using the action "noaction". "noaction" is similar to "invalid", but less will give an error beep for an "invalid" command, but not for a "noaction" command. In addition, ALL default commands may be disabled by adding this control line to the input file:

#stop

This will cause all default commands to be ignored. The #stop line should be the last line in that section of the file.

Be aware that #stop can be dangerous. Since all default commands are disabled, you must provide sufficient commands before the #stop line to enable all necessary actions. For example, failure to provide a "quit" command can lead to frustration.

Line Editing Section

The line-editing section begins with the line:

#line-edit

This section specifies new key bindings for the line editing commands, in a manner similar to the way key bindings for ordinary commands are specified in the #command section. The line-editing section consists of a list of keys and actions, one per line as in the example below.

Example

The following input file describes the set of default line-editing keys used by less:

#line-edit
\tforw-complete
\17back-complete
\e\tback-complete
^Lexpand
^Vliteral
^Aliteral
\elright
\krright
\ehleft
\klleft
\ebword-left
\e\klword-left
\ewword-right
\e\krword-right
\eiinsert
\exdelete
\kxdelete
\eXword-delete
\ekxword-delete
\e\bword-backspace
\e0home
\khhome
\e$end
\keend
\ekup
\kuup
\ejdown
^Gabort

Less Environment Variables

The environment variable section begins with the line

#env

Following this line is a list of environment variable assignments. Each line consists of an environment variable name, an equals sign (=) and the value to be assigned to the environment variable. White space before and after the equals sign is ignored. Variables assigned in this way are visible only to less. If a variable is specified in the system environment and also in a lesskey file, the value in the lesskey file takes precedence.

If the variable name is followed by += rather than =, the string is appended to the variable's existing value. This currently works only if any += lines immediately follow the same variable's original definition (with an = line), without any intervening definitions of other variables. It can append only to a variable defined earlier in the file; it cannot append to a variable in the system environment. The string is appended literally, without any extra whitespace added, so if whitespace is desired, it should be appended to the end of the preceding line. (It cannot be added to the beginning of the += string because space after the equals sign is ignored, as noted above.)

In the string after the = sign, a substring of the form ${NAME} is replaced with the value of the environment variable "NAME". The value of the variable may come from either the system environment, an earlier lesskey file, or an earlier definition in the current lesskey file. Simple text replacements can be performed by using  the syntax ${NAME/STRING/REPL}. This replaces all instances of "STRING" in the named  environment variable with the text "REPL". STRING is matched using a simple text comparison; no metacharacters are supported. An instance of slash or right curly bracket in STRING or REPL must be escaped by preceding it with two backslashes. If REPL is an empty string, all instances of STRING are removed. A slash immediately before the right curly bracket may be omitted. Multiple replacements may be performed by using the syntax ${NAME/STRING1/REPL1/STRING2/REPL2} and so on.

Conditional Configuration

If a line begins with #version followed by a relational operator and a version number, the remainder of the line is parsed if and only if the running version of less (or lesskey) matches the operator. This can be helpful if a lesskey file is used by different versions of less.

For example, suppose that a new command named 'sideways-search' is added in less version 777. Then the following line would assign the command to the Q key, but only in versions of less which support it. The line would be ignored by versions earlier than 777.

	#version >= 777  Q sideways-search

These six operators are supported:

>Greater than
<Less than
>=Greater than or equal to
<=Less than or equal to
=Equal to
!=Not equal to

The #version feature is not supported in less and lesskey before version 594. In those older versions, all #version lines are ignored.

Example

The following input file sets the -i and -S options when less is run and, on version 595 and higher, adds a --color option.

	#env
	## (Note that there must be a space at the end of the next line,
	##  to separate the --color option from the -S option.)
	LESS = -i -S 
	#version >= 595  LESS += --color=Hkc

See Also

less(1)

Warnings

On MS-DOS and OS/2 systems, certain keys send a sequence of characters which start with a NUL character (0). This NUL character should be represented as \340 in a lesskey file.

Author

Mark Nudelman
Report bugs at https://github.com/gwsw/less/issues.

Referenced By

less(1).

Version 661: 29 Jun 2024