ex
Edit text files (line editor)
TLDR
Open a file
Save and Quit
Undo the last operation
Search for a pattern in the file
Perform a regex substitution in the whole file
Insert text
Switch to Vim
SYNOPSIS
ex [options] [file ...]
PARAMETERS
-s
Silent mode, suppresses interactive feedback.
-e
Starts in ex mode, even if invoked as vi.
-R
Opens the file in read-only mode.
-c
Executes the specified ex command after opening the file.
-l
Sets LISP mode for improved indentation and bracket matching.
-r
Recovers a crashed editor session.
-t
Edits the file containing the specified tag, positioning the cursor at the tag definition.
-v
Starts in vi (visual) mode. This is often how vi itself is invoked.
-w
Sets the default window size (number of lines) for the visual display.
-x
Enables encryption/decryption of the file during editing.
-Z
Starts in restricted mode, limiting shell escape and file writing capabilities.
One or more text files to be opened and edited.
DESCRIPTION
ex is a powerful line-oriented text editor that serves as the foundation for the more commonly known screen-oriented editor, vi. Unlike vi, which provides a visual, full-screen interface, ex operates by processing text line by line, requiring users to specify line numbers or patterns for most operations. It's particularly well-suited for batch processing, scripting, or making global changes to files where a visual interface isn't necessary or practical. Many commands in vi's command mode are actually ex commands. Users can enter ex mode from vi by typing a colon (:) followed by an ex command. While less common for interactive use today due to modern editors, its capabilities remain valuable for automated text manipulation.
CAVEATS
ex has a steep learning curve for interactive use compared to modern screen editors. It is primarily useful for batch operations or scripting rather than day-to-day interactive text editing. Its line-oriented nature can be confusing for users accustomed to GUI or full-screen CLI editors.
COMMON EX COMMANDS
Many ex commands are frequently used within vi by preceding them with a colon (':').
Here are a few common examples:
':q': Quit the editor.
':w': Write (save) the current file.
':wq' or ':x': Write and quit the editor.
':%s/old/new/g': Globally substitute all occurrences of 'old' with 'new' throughout the entire file.
':
':set : Set editor options (e.g., 'set nu' to display line numbers, 'set ic' for ignore case in searches).
':!': Execute a shell command from within the editor (e.g., ':!ls').
HISTORY
ex was developed at the University of California, Berkeley, by Bill Joy as an extended version of the `ed` editor, providing more powerful commands and regular expression capabilities. It became the foundational layer for the visual editor (vi), also created by Joy to provide a screen-oriented interface to ex's capabilities. Its development was a crucial step in the evolution of Unix text editors, directly leading to the highly influential vi and its modern descendants like vim.