LinuxCommandLibrary

sensible-editor

Open a file in a user's preferred editor

TLDR

Open a file in the default editor

$ sensible-editor [path/to/file]
copy

Open a file in the default editor, with the cursor at the end of the file
$ sensible-editor + [path/to/file]
copy

Open a file in the default editor, with the cursor at the beginning of line 10
$ sensible-editor +10 [path/to/file]
copy

Open 3 files in vertically split editor windows at the same time
$ sensible-editor -O3 [path/to/file1 path/to/file2 path/to/file3]
copy

SYNOPSIS

sensible-editor [file...]

PARAMETERS

[file...]
    The files to open with the selected editor. If no file is specified, the editor will likely open with an empty buffer.

DESCRIPTION

The `sensible-editor` command is a Debian-specific utility designed to select and invoke a text editor that is considered 'sensible' for the user and system. It attempts to provide a user-friendly default editor, considering factors like the `EDITOR` and `VISUAL` environment variables, and the available installed editors. If no explicit editor is specified, it chooses from a predefined list of popular text editors like `nano`, `vim.tiny`, or `emacs`.

The command prioritizes using the `EDITOR` environment variable, then `VISUAL`, and if neither is set, it looks at the alternatives system (using `update-alternatives --config editor` for manual configurations). It is useful for scripts or programs that need to launch a text editor without requiring the user to manually specify the editor each time. It ensures that a reasonable editor is always available, which improves usability. The primary benefit lies in its intelligent default selection mechanism. Instead of directly launching a hardcoded editor, it makes sure that the system launches an editor that the user prefers or which is installed.

CAVEATS

The behavior of `sensible-editor` can be influenced by environment variables. The precise order of editor selection might vary across different Debian-based distributions or versions. It relies on the 'alternatives' system in Debian, which might require initial configuration for the `editor` alternative.

ENVIRONMENT VARIABLES

The `sensible-editor` command relies heavily on the `EDITOR` and `VISUAL` environment variables. EDITOR usually defines the default editor for console based applications, while VISUAL is often used for visual, full-screen editors. Setting these variables allows users to specify their preferred editor, which `sensible-editor` will then respect. If both are set, `EDITOR` is usually given priority.

ALTERNATIVES SYSTEM

Debian's alternatives system manages symbolic links to provide a consistent interface for commands and utilities. `sensible-editor` uses the alternatives system to determine the default editor when the `EDITOR` and `VISUAL` variables are not set. You can use the command update-alternatives --config editor to configure the alternatives system for the editor manually. This is especially useful for administrators who need to configure a system-wide default editor.

HISTORY

The `sensible-editor` command was created to standardize editor selection in Debian-based systems. Before its introduction, scripts and applications often relied on hardcoded editor paths or required extensive user configuration. The goal was to provide a consistent and user-friendly way to invoke a text editor across the system. It helps ensure that a GUI-less, console-based text editor is available even in minimal environments. It's primary aim is to allow the system to decide the best suited editor for command line usage and for systems where only terminal editors are supported.

SEE ALSO

editor(1), nano(1), vim(1), emacs(1), update-alternatives(8)

Copied to clipboard