Text editor

From Gentoo Wiki
Jump to:navigation Jump to:search
Resources

A text editor is a program to create and edit text files. Although it is not impossible to edit files without using one, text editors make it easy, and are handy for editing configuration files.

The Gentoo @system set contains the virtual/editor package to make sure at least one editor is installed.

Default, fallback, and virtual packages

As with most things Gentoo, text editor choice is up to the user. As a text editor will be necessary during and just after installation, the virtual package, virtual/editor (part of the system set), will pull in app-editors/nano[1] (as the first "any of many" dependency of the ebuild) as a fallback - until another "virtual/editor" package is emerged.

Thus, after a stage 3 installation, the nano command will be available once chrooted to a newly installed Gentoo. As the stage 3 tarballs only contain packages that are strictly necessary for every system, Nano will be the only text editor available in the stage 3 chroot. A replacement editor may be emerged on the new system, as soon as the Gentoo ebuild repository is installed and optionally updated.

The default editors for the CLI will be used by many programs to determine which text editor to start up, when needed. Programs such as CLI file managers will use this default, or when invoking an editor from bash using Ctrl+x Ctrl+e. The default editors are set using the VISUAL and EDITOR environment variables. Generally, VISUAL will take precedence over EDITOR, which is used for less capable terminals.

See the setting system default section.

Tip
The Minimal Installation CD, available for download from the Gentoo website, includes the Nano, Emacs, and vi editors. After chrooting to a new environment for installation, the same editors will not all be available, though any editor of choice may now be installed.
Note
When the first editor that is a dependency of the virtual/editor package is emerged, this will satisfy the "any of many" dependency, so Nano will no longer be required. emerge --select app-editors/nano to add Nano to the world set, to prevent emerge --ask --depclean from uninstalling Nano.

Available software

Text editor options can be found online in the app-editors category or by running:

user $eix "app-editors/*"

CLI editors

Name Package Skill level Features Description
Emacs app-editors/emacs Advanced Huge Class of powerful, extensible, self-documenting text editors.
Micro app-editors/micro Easy Advanced Modern and intuitive terminal-based text editor. Still in testing branch as of 2022-11.
Nano app-editors/nano Easy Advanced Easy to use text editor.
Neovim app-editors/neovim Advanced Huge Vim fork focused on extensibility and agility.
Vim app-editors/vim Advanced Huge Text editor based on the vi text editor.

See the vi article for more vi(like) editors.

GUI editors

Name Package Description
Emacs app-editors/emacs Class of powerful, extensible, self-documenting text editors.
Gedit app-editors/gedit Text editor for the GNOME desktop.
GVim app-editors/vim Text editor based on the vi text editor.
leafpad app-editors/leafpad Simple GTK2 text editor
Kate kde-apps/kate KDE text editor. Development oriented.
Mousepad app-editors/mousepad Bare-bones text editor for Xfce that starts up extremely quickly.
pluma app-editors/pluma Small and lightweight UTF-8 text editor for the MATE environment.
scite app-editors/scite Very powerful editor for programmers. Oriented towards source editing.
Vscodium app-editors/vscodium Free/Libre Open Source Software Binaries of Microsoft's VSCode.

Visudo editor

Due to the sensitive nature of /etc/sudoers it may only edited via the visudo command which in turn is limited to a predefined selection of editors. Type man visudo for more information.

Setting system default

A system wide default text editor is defined in the /etc/env.d/99editor file, for example:

FILE /etc/env.d/99editorSystem wide text editor default
EDITOR="/usr/bin/vim"

The system default editor can be set with the eselect utility, which modifies this file automatically. To list available editors (install editor of choice for it to become available with eselect editor):

root #eselect editor list
Available targets for the EDITOR variable:
  [1]   /bin/nano
  [2]   /bin/ed
  [3]   /usr/bin/emacs
  [4]   /usr/bin/ex
  [5]   /usr/bin/vi
  [ ]   (free form)

If using Vim or Neovim, select vi, then see the next section.

To set a new editor, replace <NUMBER> in the following command with a number corresponding to the text editor of choice:

root #eselect editor set <NUMBER>

Next, the environment must be updated by running the following command:

root #. /etc/profile

User's EDITOR environment variable will now have the default value selected. Users may change this value however, in a running shell, or automatically on login shell startup.

Note
sudo does not preserve the user's environment variables, so when using sudo, expect that the default editor may not be the same as the currently running user's.
Tip
To set the VISUAL variable, follow the same procdure, but with eselect visual.

The old method of setting the EDITOR variable in /etc/rc.conf is no longer supported. See this article for details.

Caveats

Binary files

Many text editors won't be able to handle binary files. Use a hex editor for such files.

If binary data gets improperly output to the terminal, it can sometimes "garble" the display, see this section of the terminal emulator article for help.

See also

References