Home / Alt manpages / select-editor(1)

  • select-editor(1)
  • User command
  • linux

Set the per-user editor used by Debian's sensible-editor

You will choose an installed text editor for your user account, confirm what was saved, and understand when that choice is ignored. The change is local to your account and normally takes about five minutes. You need a Debian or Debian-derived system with sensible-utils installed; this guide uses sensible-utils 0.0.22 as installed on the reference system.

1. Check the command and the available editors

Run the command without sudo. select-editor is a per-user tool, so it writes below your home directory rather than changing the system-wide alternatives configuration.

$ command -v select-editor
/usr/bin/select-editor
$ dpkg-query -W -f='${Package} ${Version}\n' sensible-utils
sensible-utils 0.0.22
$ update-alternatives --list editor
/bin/ed
/bin/nano
/usr/bin/vim.basic
/usr/bin/vim.tiny

Your list can differ. The alternatives system may know more than one path for the editor name, and select-editor presents those paths in its own order. Do not assume that option 1 is always nano, or that a particular editor is installed just because it appears in an example.

2. Choose the editor interactively

Start the selector:

$ select-editor

Select an editor.  To change later, run 'select-editor'.
  1. /bin/nano        <---- easiest
  2. /usr/bin/vim.basic
  3. /usr/bin/vim.tiny
  4. /bin/ed

Choose 1-4 [1]:

Enter the number beside the editor you actually want, then press Enter. The bracketed number is the default shown by the installed script. On the reference system, pressing Enter at this prompt chooses /bin/nano, but the default and the list are installation-dependent. If you are unsure which editor suits you, stop at the prompt and test the candidates separately rather than selecting at random.

The command writes a shell assignment to ~/.selected_editor. It does not install an editor, edit your shell startup files, or alter the system-wide editor alternative. A successful selection ends with exit status 0:

$ printf '%s\n' "$?"
0

A system with zero or one usable alternative may have nothing to select, and the installed script can then return a non-zero status without creating a useful choice. That is a condition to investigate, not a reason to run the command repeatedly.

Checkpoint: confirm what was saved

Read the file as data before relying on it:

$ sed -n '1,5p' "$HOME/.selected_editor"
# Generated by /usr/bin/select-editor
SELECTED_EDITOR="/bin/nano"

The path must be an editor you recognise and can execute. The file is intended to be sourced by sensible-editor, so do not append arbitrary shell commands to it. If the file is missing, empty, or contains an unexpected value, return to step 2 and make a deliberate selection.

3. Verify the selection without opening an editor

Sourcing the file in a short shell and printing the variable checks the saved value without launching a full-screen editor:

$ sh -c '. "$HOME/.selected_editor" && printf "SELECTED_EDITOR=%s\n" "$SELECTED_EDITOR"'
SELECTED_EDITOR=/bin/nano

That confirms the file contains a valid assignment. It does not prove that the editor can open every file or that your terminal supports it. To test the chosen program itself, use a harmless temporary file in a working directory and quit the editor normally. Do not use a valuable document for the first test.

4. Understand the overrides that can hide your choice

sensible-editor checks environment variables before it uses ~/.selected_editor. In the installed sensible-utils behaviour, VISUAL takes precedence over EDITOR, and both take precedence over SELECTED_EDITOR. A non-empty variable can therefore make a correctly saved selection appear to have no effect.

$ printf 'VISUAL=%s\nEDITOR=%s\nSELECTED_EDITOR=%s\n' \
    "${VISUAL-}" "${EDITOR-}" "${SELECTED_EDITOR-}"
VISUAL=/usr/bin/vim
EDITOR=/usr/bin/vim
SELECTED_EDITOR=

To inspect the saved choice while temporarily ignoring the first two variables, use:

$ env -u VISUAL -u EDITOR sh -c \
    '. "$HOME/.selected_editor" && printf "%s\n" "$SELECTED_EDITOR"'
/bin/nano

This command changes only the environment of that one shell process. It does not unset anything in your current shell. If your shell startup files export VISUAL or EDITOR, change those files only if you want the override to be permanent. Otherwise, unset the variable in the relevant session when you want the per-user selection to be used:

$ unset VISUAL EDITOR

That affects the current shell and its child processes. Open a new shell or source your normal startup file if you need to restore the environment later.

5. Recover from a wrong selection

Run select-editor again and choose the replacement. This is the normal undo operation and preserves the same per-user scope:

$ select-editor

If you need to restore the previous value manually, make a backup before editing the generated file:

$ cp --preserve=mode,ownership,timestamps "$HOME/.selected_editor" "$HOME/.selected_editor.bak"
$ select-editor

Keep the backup until the new choice works. To roll back, replace the generated file with the backup:

$ cp --preserve=mode,ownership,timestamps "$HOME/.selected_editor.bak" "$HOME/.selected_editor"
$ sh -c '. "$HOME/.selected_editor" && printf "%s\n" "$SELECTED_EDITOR"'

Do not delete the backup automatically. Removing it is irreversible, and it is unnecessary once you have checked the replacement.

Common traps

  • Using sudo: it selects an editor for the root account and may create or change root's /root/.selected_editor. It does not configure your normal user.
  • Expecting a system-wide change: select-editor writes a per-user preference. System-wide alternatives are managed separately with update-alternatives.
  • Ignoring VISUAL and EDITOR: either variable can override the saved preference. Check them before changing the selection again.
  • Editing the file as a configuration language: it is a shell fragment containing a value, not a general-purpose editor configuration. Keep the assignment simple and quoted.

Done means

  • The chosen program appears in ~/.selected_editor as SELECTED_EDITOR.
  • The file can be sourced by a short shell command and prints the expected path.
  • You know whether VISUAL or EDITOR overrides the saved choice.
  • You can rerun select-editor to change the preference, or restore the backup if needed.
  • No system-wide alternative, package installation, or privileged account was changed.