LinuxCommandLibrary

lesskey

Customize the less pager keybindings

SYNOPSIS

lesskey [-o output_file] [-b] [-h | --help] [-V | --version] [-v] [input_file]

PARAMETERS

-o output_file
    Specifies the name of the output binary file. Defaults to ~/.less/lesskey.bin if not provided.

-b
    Used for backward compatibility with older versions of `lesskey`; generally not needed.

-h, --help
    Displays a help message and exits.

-V, --version
    Displays version information and exits.

-v
    Enables verbose mode, printing comments from the input file to standard error during compilation.

input_file
    The path to the plain text file containing the key binding definitions. If omitted, `lesskey` reads from standard input.

DESCRIPTION

`lesskey` is a utility used to create and manage custom key bindings for the less pager. It processes an input file containing user-defined key sequences and their corresponding actions, compiling it into a binary file, typically named lesskey.bin. This binary file is then read by less upon startup, allowing users to personalize their interactive browsing experience. This provides a powerful way to extend less's functionality, add new shortcuts, or modify existing ones to better suit individual workflows, significantly enhancing productivity for command-line text viewing and navigation.

CAVEATS

`lesskey` creates a binary file (lesskey.bin) from a human-readable plain text configuration file. This binary file must be correctly placed (usually in ~/.less/ or specified via LESSKEY_BIN environment variable) for less to find and use it. Errors in the input `lesskey` file's syntax can lead to unexpected behavior or less failing to load the custom bindings. Users must re-run `lesskey` every time they modify their plain text configuration file for the changes to take effect in less.

KEY BINDING FILE FORMAT

The input file for `lesskey` consists of lines defining key sequences and their corresponding actions. Lines starting with # are comments. Key sequences can be specified as literal characters, or using special notations like ^X for Ctrl-X, \eX for Alt-X, and \e for the Escape key. Actions correspond to less internal commands (e.g., quit, next-file, search-forward). Key bindings can be defined in GLOBAL or COMMAND sections, affecting when they are active.

ENVIRONMENT VARIABLES

The behavior of `lesskey` and less regarding key binding files can be influenced by environment variables. LESSKEY_FILE can specify an alternative input key binding file for `lesskey` to process. LESSKEY_BIN can define the path to the compiled binary key binding file that less should load, overriding the default location (~/.less/lesskey.bin).

HISTORY

The `lesskey` utility is an integral part of the less pager project, which was originally written by Mark Nudelman. It was introduced to provide a robust and flexible mechanism for users to customize key bindings, moving beyond hardcoded defaults. Its design to compile a plain text file into a binary format (lesskey.bin) reflects a common pattern in Unix-like systems for efficient loading of configuration data by frequently used applications like less. This approach ensures quick startup times for less while still offering extensive personalization options.

SEE ALSO

less(1), more(1), lesspipe(1), man(1)

Copied to clipboard