Home Technical Support vi Editor in Practical DevSecOps Labs: Modes, Saving, and Exiting

vi Editor in Practical DevSecOps Labs: Modes, Saving, and Exiting

Last updated on Sep 03, 2026

vi Editor in Practical DevSecOps Labs: Modes, Saving, and Exiting

The vi editor is one of the most commonly available terminal-based text editors in Linux environments. Understanding its modes of operation is essential for editing files in the Practical DevSecOps labs.


Table of Contents

  1. Opening a File
  2. Modes of Operation
  3. Essential Commands
  4. Common Questions

Opening a File

vi security-report.json    # opens existing file or creates new one
vi foo.txt                 # creates a new file if it doesn't exist

Modes of Operation

vi has three modes of operation. Knowing which mode you're in is the most important skill for using this editor.

Command Mode (default)

When you open vi, you are in Command Mode by default. In this mode:

  • You can navigate with arrow keys or h/j/k/l
  • You can enter commands like :q, :wq, :q!
  • Typing characters does not insert text

Insert Mode

Press i to enter Insert Mode. In this mode:

  • You can type and edit text normally
  • The bottom of the screen shows -- INSERT --

Line Mode (ex mode)

Press : (colon) from Command Mode to enter Line Mode. The cursor moves to the bottom of the screen, where you can type commands like:

  • :wq — save and exit
  • :q! — exit without saving
  • :w — save without exiting

Essential Commands

Workflow: Edit a file

  1. Open the file: vi foo.txt
  2. Press i to enter Insert Mode
  3. Type your text
  4. Press Esc to return to Command Mode
  5. Type :wq and press Enter to save and exit

Workflow: Read-only, no changes

  1. Open the file: vi filename
  2. Navigate with arrow keys (you're already in Command Mode)
  3. Type :q and press Enter to exit

Pasting text without Insert Mode

You can paste clipboard content directly into the file using:

  • macOS: Cmd + V
  • Windows: Ctrl + Shift + V
  • Linux: Ctrl + Shift + V (GNOME Terminal) or Shift + Insert

Common Questions

Question Answer
How do I exit vi? Press Esc, then type :q (quit) or :q! (quit without saving).
How do I save my changes? Press Esc to return to Command Mode, then :wq.
I'm stuck in vi and can't type — what's wrong? You're in Command Mode. Press i to enter Insert Mode.
How do I undo a change? In Command Mode, press u to undo. Press Ctrl + R to redo.
What's the difference between vi and vim? vim is an enhanced version of vi with additional features. Both use the same core commands.

Wrap-Up

vi is a powerful but initially intimidating editor. Remember the three modes: Command (default, for navigation), Insert (for typing), and Line (:, for commands). Master i to insert, Esc to return to command mode, and :wq to save and exit, and you'll handle any file editing task in the labs.