
VI Editor: Modes, Common Operations, and Use Cases
The vi editor is a powerful and lightweight text editor available on almost every Unix/Linux system. It is widely used by DevOps Engineer for editing configuration files, scripts, and code directly from the terminal.
Modes
vi operates mainly in 3 modes:
- Command Mode: Default mode for navigation and commands.
- Insert Mode: For inserting and editing text.
- Last line: To save, quit and exit from vi.
Switching Modes
- Start vi:
vi hello.txt
- It will create a file named “hello.txt” and open it as command mode by default
- To switch from Command to Insert Mode: Press
i
(although has other options as well to switch,i
is commonly used for insert) - Return to Command Mode: Press
Esc
- Enter Last-Line Mode: Press
:
Use Case
vi is ideal for:
- Editing configuration files on remote servers.
- Quick edits to scripts and code.
- Situations where minimal resources are available.
- Environments where GUI editors are not accessible.
Summary
Learning vi editor basics can greatly improve your efficiency in managing Linux systems. Its modal nature and keyboard shortcuts make it fast and reliable for everyday tasks.