Linux Basic Commands
9. vi
vi Command in Linux
vi is a text editor in Linux, used to view and edit files directly in the terminal.
It's one of the most powerful and widely available editors on Unix/Linux systems.
🔹 Basic Syntax:
vi filename
🔹 Example:
vi notes.txt
👉 This opens (or creates, if not exists) a file named notes.txt for editing.
🔹 Modes in vi:
-
Normal Mode (default when you open
vi)
– For navigation and commands -
Insert Mode
– For typing text
– Pressito enter Insert mode -
Command Mode
– For saving, quitting, searching
– Press:to enter command mode
🔹 Basic Commands:
|
Action |
Key |
|---|---|
|
Enter Insert Mode |
|
|
Save File (Command Mode) |
|
|
Quit |
|
|
Save & Quit |
|
|
Quit without saving |
|
|
Delete a line |
|
|
Copy a line |
|
|
Paste |
|
|
Move up/down |
|
|
Move left/right |
|
🔹 Example Flow:
-
Open a file:
vi hello.txt
-
Press
i→ Enter Insert Mode -
Type:
Hello, this is my first vi file!
-
Press
Esc→ Go back to Normal Mode -
Type
:wq!→ Save and quit
Try with Linux Practice