Text
ex
Line-oriented text editor, the base of vi.
Additional Notes
ex is the line-editor mode of vi. When you run vi, you are actually running ex's visual mode. The ex command provides the same line-oriented editing commands that are available in vi's command mode when preceded by :. It supports the full ex command set: search and replace, file operations, buffer management, and scripted editing.
ex can be used interactively as a line editor or driven by scripts for batch text processing. It is standardized by POSIX and is the direct successor of ed. The ex command language includes vi's command-line commands (:s, :g, :w, :q, etc.) without the visual interface.
Syntax
ex [options] [file...]
Parameters
file: File to edit.
Common Options
-R: Open files in read-only mode (likeview).-r file: Recover the specified file after a crash.-s: Enter batch mode with suppressed prompts (for scripting).-c command,--cmd command: Run a command after opening the file.-t tag: Edit the file containing the specified tag.-w number: Set the window size for the^Zcommand.-E: Display text with tabs expanded.-v: Start in visual mode (equivalent to runningvi).
Examples
ex file.txt
Open file.txt in ex line-editor mode.
ex -s file.txt <<< $'%s/foo/bar/g\nwq'
Replace all occurrences of foo with bar and save.
ex -c '%s/old/new/g' -c 'wq' file.txt
Replace text from the command line and quit.
ex -R file.txt
Open a file in read-only mode.
Practical Notes
- All
vicolon commands (:s,:g,:w,:q, etc.) areexcommands. - In batch mode (
-s),exsuppresses prompts and error messages, making it suitable for scripted editing. exis often used as the editor forcrontab -eand other tools that require a POSIX-standard editor.- To switch to visual mode from within
ex, typeviorvisual. - The
excommand set is documented in theexman page (section 1) and the POSIX specification.