Text Editors

Text Editors

Introduction

Most MidnightBSD configuration is done by editing text files, so it is a good idea to become familiar with a text editor. MidnightBSD comes with a few editors as part of the base system, and many more are available through mports.

A simple editor to learn is ee, which stands for Easy Editor. More experienced users often prefer vi, which is also included in the base system. Many applications that need to open a text editor use the EDITOR environment variable to decide which one to launch. See the Shells documentation for information on setting EDITOR.

Base System Editors

These editors are part of the MidnightBSD base system and are available on any installed system without installing additional packages.

ee — Easy Editor

ee stands for Easy Editor and is the most approachable editor in the base system for new users. All available commands are listed at the top of the screen, so you do not need to memorize keyboard shortcuts before getting started.

To open a file:

ee filename

The caret symbol (^) in the on-screen menu represents the Ctrl key, so ^e means Ctrl+e. Navigation is done with the arrow keys. To exit, press Escape and then choose leave editor from the menu. If the file has been modified, ee will prompt you to save before exiting.

Some useful key bindings in ee:

vi

vi is a powerful modal text editor included in the base system. It has two primary modes: command mode, where keystrokes are interpreted as editor commands, and insert mode, where keystrokes are inserted as text. The editor starts in command mode.

To open a file:

vi filename

Essential vi commands:

vi has a steeper learning curve than ee, but it is available on virtually every Unix-like system, making it worth learning for anyone who works across multiple machines or needs to edit files in minimal environments such as single-user mode.

mined — MINimal EDitor

mined is a simple, screen-oriented text editor included in the base system. It is designed to be easy to use and was one of the earliest screen editors available on Unix systems. mined uses control-key commands for its operations and is a reasonable alternative to ee for users who prefer a slightly different interface.

To open a file:

mined filename

Some useful mined key bindings:

Editors from mports

The following editors are available through mports and offer additional features or graphical interfaces not found in the base system editors.

vim

vim (Vi IMproved) extends vi with syntax highlighting, multi-level undo, split windows, plugin support, and many other features. It is one of the most popular editors among developers and system administrators. vim retains full compatibility with vi key bindings while adding a large set of additional capabilities.

Install vim from mports:

mport install vim

vim reads ~/.vimrc for user configuration. A basic configuration to enable syntax highlighting and line numbers:

syntax on
set number
set tabstop=4
set expandtab

vim can be started in read-only mode with view filename, or opened at a specific line number:

vim +42 filename

To search and replace across an entire file from vim's command mode:

:%s/oldtext/newtext/g
nano

nano is a straightforward terminal editor modeled after the Pico editor. Like ee, it displays available commands at the bottom of the screen, making it easy to use without prior knowledge. It supports syntax highlighting, search and replace, and soft-wrapping of long lines.

Install nano from mports:

mport install nano

To open a file:

nano filename

Key bindings use the same caret notation as ee, where ^ means Ctrl:

jupp — Joe's Own Editor

jupp is a port of Joe's Own Editor (JOE), a terminal editor with WordStar-style key bindings. It supports syntax highlighting, multiple buffers, and a built-in help system accessible at any time. Users familiar with WordStar or the Borland IDE will find the key layout natural.

Install jupp from mports:

mport install jupp

To open a file:

jupp filename

Press ^K H (Ctrl+K then H) at any time to toggle the built-in help screen, which lists all available commands.

gedit

gedit is the default graphical text editor for the GNOME desktop environment. It provides a clean, modern interface with syntax highlighting for many programming languages, a plugin system, and integration with GNOME services. gedit requires a running graphical environment (X11 or Wayland).

Install gedit from mports:

mport install gedit

To open a file from the terminal:

gedit filename &
mousepad

mousepad is the default graphical text editor for the Xfce desktop environment. It is lightweight, starts quickly, and supports syntax highlighting, line numbers, and basic search and replace. mousepad is a good choice on systems where a minimal graphical editor is preferred without pulling in GNOME dependencies.

Install mousepad from mports:

mport install mousepad

To open a file from the terminal:

mousepad filename &
Sublime Text

Sublime Text is a feature-rich graphical editor popular among developers for its speed, multiple cursors, command palette, and large ecosystem of plugins. The linux-sublime package provides the Linux binary running under MidnightBSD's Linux binary compatibility layer.

Linux binary compatibility must be enabled before installing. See the Linux Binary Compatibility documentation for setup instructions.

Install Sublime Text from mports:

mport install linux-sublime

To open a file from the terminal:

sublime_text filename &

Sublime Text is free to evaluate but requires a license for continued use. License and pricing information is available on the Sublime Text website.

Setting a Default Editor

Many programs that need to open a text editor consult the EDITOR and VISUAL environment variables. Examples include crontab -e, git commit, and chsh. Setting these variables in your shell's startup file ensures your preferred editor is used consistently.

For Bourne-compatible shells (sh, bash, zsh, mksh), add to ~/.profile or ~/.bashrc / ~/.zshrc:

export EDITOR=vim
export VISUAL=vim

For tcsh, add to ~/.tcshrc or ~/.cshrc:

setenv EDITOR vim
setenv VISUAL vim

Replace vim with the full path or name of your preferred editor, for example /usr/local/bin/nano or simply nano if it is on your PATH.

For more information on environment variables and shell configuration, see the Shells documentation.