vi
Edit text-based files
TLDR
View documentation for the original command
SYNOPSIS
vi [options] [file ...]
The vi command starts the visual editor. If file arguments are provided, vi opens them for editing. If no files are specified, vi opens an empty buffer.
PARAMETERS
-r file
Recovers file after a system crash, attempting to restore unsaved changes.
-R
Opens the file in read-only mode, preventing accidental writes and protecting the file.
-c command
Executes the specified command (an ex command) immediately upon starting vi, useful for initial setup.
-t tag
Jumps to the specified tag (defined in a tags file, usually generated by ctags) within the appropriate file.
-s script
Runs the ex script commands from the specified file after starting, useful for automation.
DESCRIPTION
vi (visual editor) is a screen-oriented text editor originally created for the Unix operating system. Developed by Bill Joy in 1976 for an ADM-3A terminal, it was built upon the ex line editor, which itself was based on ed. Unlike contemporary editors that operate in a single mode, vi is famous for its modal editing paradigm, primarily distinguishing between command mode and insert mode.
In command mode, keystrokes are interpreted as commands (e.g., for navigation, deletion, copying); in insert mode, they are interpreted as text to be inserted into the document. This design allows for highly efficient text manipulation once mastered, as users can perform complex operations with minimal keystrokes without needing to use a mouse. vi became a standard component of all Unix and Unix-like systems, including Linux, making it an essential tool for system administrators and developers due to its availability even in minimal environments, its speed, and its low resource footprint. While its learning curve is steep, its power and ubiquity ensure its continued relevance.
CAVEATS
vi has a notably steep learning curve due to its unique modal interface, which can be confusing for beginners accustomed to single-mode editors. Users must constantly switch between command and insert modes, which requires memorizing a significant number of commands. Its text-based interface lacks graphical elements like menus or scrollbars, making navigation and operation less intuitive without prior knowledge. Original vi implementations also offered limited undo capabilities compared to modern editors, and its command syntax can be very terse and cryptic.
MODES OF OPERATION
vi primarily operates in three distinct modes:
Command Mode: The default mode upon opening vi. Keystrokes are interpreted as commands for navigation, deletion, copying, pasting, and other operations. You return to this mode by pressing the Esc key.
Insert Mode: Entered by commands like i (insert), a (append), o (open new line), or R (replace). Keystrokes are inserted directly into the text buffer as content. All text input occurs in this mode.
Last-Line / Ex Mode: Entered by typing : (colon) or / (forward slash) from command mode. This allows executing ex commands (e.g., saving, quitting, search/replace, executing shell commands) which are typed at the bottom of the screen.
BASIC NAVIGATION AND EDITING
Fundamental vi commands, executed from command mode, include:
hjkl: (left, down, up, right) for cursor movement.
i, a, o: (insert, append, open) to enter insert mode.
x: delete character under cursor.
dd: delete current line.
yy: yank (copy) current line.
p: put (paste) after cursor/line.
:/pattern: search forward for a pattern.
:w: write (save) changes.
:q: quit.
:wq or ZZ: save and quit.
HISTORY
vi was created by Bill Joy at the University of California, Berkeley, in the late 1970s as the visual interface for the ex line editor. It quickly became part of the BSD Unix distribution. Its efficiency, low resource usage, and the ability to work over slow terminal connections made it indispensable in the early days of Unix. While many modern alternatives exist, vi's core design principles and ubiquity across Unix-like systems ensure its continued relevance, especially in system administration, scripting, and embedded environments where full-featured editors like vim might not be available. Its influence is seen in numerous text editors that incorporate vi-like key bindings and modes.