Operating Systems & Administration

[Day 5] 2. VI Editor

D
DITISS Admin
••3 min read

VI Editor Overview

VIM stands for VI IMproved, an enhanced version of the VI text editor. It's a powerful CLI (Command Line Interface) editor commonly used in Linux systems.

1. Installation Commands:

  • Install VIM using

    apt
    :
    sudo apt-get install vim

  • Install VIM using

    snap
    :
    sudo snap install vim

    Both

    snap
    and
    apt
    are package managers that install various software packages on your system.


2. VIM Modes

VIM operates in three modes:

  1. Command Mode:
    • Access by pressing
      Esc
      .
    • This mode allows you to give commands to save, copy, cut, and perform other actions.
  2. Text Mode / Insert Mode:
    • Access by pressing
      i
      .
    • This mode is used to add or insert content into the file.
  3. Visual Mode:
    • Access by pressing
      v
      .
    • Used to select text within the editor.

By default, the VI editor opens in Command Mode.


3. Common VIM Commands

File Operations:

  • :w
    : Save or write to the file.
  • :q
    : Quit or exit the VI editor.
  • :wq
    : Save and quit the file.

Copy (Yank) Commands:

  • :y
    : Copy the current line.
  • yy
    : Copy the current line.
  • :ny
    : Copy the
    n
    th line.
  • nyy
    : Copy the next
    n
    lines from the current line.
  • m,ny
    : Copy lines from line
    m
    to line
    n
    .
  • yw
    : Copy the next word.
  • y$
    : Copy from the cursor position to the end of the line.
  • y^
    : Copy from the start of the line to the cursor position.

Cut (Delete) Commands:

  • :d
    : Cut the current line.
  • dd
    : Cut the current line.
  • :nd
    : Cut the
    n
    th line.
  • ndd
    : Cut the next
    n
    lines from the current line.
  • m,nd
    : Cut lines from line
    m
    to line
    n
    .

Delete Commands (without pasting):

  • :d
    : Delete the current line.
  • dd
    : Delete the current line.
  • :nd
    : Delete the
    n
    th line.
  • ndd
    : Delete the next
    n
    lines from the current line.
  • m,nd
    : Delete lines from line
    m
    to line
    n
    .

Paste and Undo:

  • p
    : Paste the copied line.
  • u
    : Undo the last action.

Read Next

8/26/2026

[Day 5] 3. Shell Scripting or Shell Programming

### Shell Scripting Overview **Shell scripting** is interpreted by the shell itself and is mainly used for: - Automation - Configuration - Wri...

8/26/2026

[Day 6] 1. Spacing in Shell Scripting

#### **Assignment Operator** - When writing a variable assignment, there should **not** be any spaces between the variable name, assignment operato...