Modes
vi mainly uses command mode and insert mode. Command mode is for navigation and operations; insert mode is for typing text.
Solaris · VI Editor
Solaris · Lesson 7
Master vi editor for configuration editing. Search, replace and navigation tips. Editing system files safely. Must have skill for Unix admins.
On almost every Unix and Solaris system, vi is guaranteed to be present. Even if you prefer other editors, knowing vi is essential when you connect to new servers or minimal installations.
This lesson focuses on the 20% of vi commands you use 80% of the time as a system administrator: opening files, moving around, making small edits and saving safely.
vi mainly uses command mode and insert mode. Command mode is for navigation and operations; insert mode is for typing text.
When you open a file in vi, you edit a buffer in memory. The file is only changed on disk when you write it with :w or :wq.
Powerful search (/) and change commands (c, d, y) make it quick to edit configs without a mouse.
Try each of the following flows in your Solaris lab. Don't worry about memorising everything at once—repeat them a few times and they will become natural.
Use vi filename to open a file. If you made a mistake, you can exit without saving using :q! from command mode.
The most basic workflow: open a file, enter insert mode with i, type, then save and quit with :wq.
Learn how to move between lines and search for specific strings using /pattern.
Always make a backup before editing important system files. Then use vi to make a small, controlled change.
Use u to undo, yy to yank (copy) a line and p to paste it below the cursor.
cp sshd_config sshd_config.bak.diff to confirm exactly what changed.:q! to exit without saving and start again.Once you are comfortable with vi, editing ZFS, SMF and network configuration files becomes much easier.