Mastering Vim Editor in Linux (With Deep Explanation & Practical Examples)

 

✅Mastering Vim Editor in Linux (With Deep Explanation & Practical Examples)



Vim Editor: The Ultimate Guide (With Examples for Beginners to Advanced Users)

When it comes to text editors in Linux, Vim is one of the most powerful, lightweight, and flexible tools ever built. Whether you're editing configuration files, writing code, or managing servers, learning Vim can save you enormous time and make you a more efficient Linux user.

But many beginners feel Vim is hard — until they learn it properly.

This blog will teach you Vim in deep, with easy explanations and practical examples.
Let’s begin! 🚀


🟢 What is Vim?

Vim stands for Vi Improved — a feature-rich version of the classic vi editor.

✔ Pre-installed on almost all Linux distros
✔ Works inside terminal
✔ Keyboard-friendly
✔ Extremely fast
✔ Ideal for system admins, developers, DevOps, and Linux power users


🔵 Modes in Vim (The MOST Important Concept)

Vim works in three major modes:

1️⃣ Normal Mode

Used for navigation, deleting, copying, pasting.

Enter Normal Mode:

Press ESC

2️⃣ Insert Mode

Used to type text.

Enter Insert Mode:

i → insert at cursor I → insert at beginning of line a → append after cursor A → append at end of line o → new line below O → new line above

3️⃣ Command Mode

Used for saving, quitting, searching, replacing.

Enter Command Mode:

Press :

🟠 How to Open & Use Vim

Open a File

vim filename.txt

Create a New File

vim myfile.conf

Open File in Read-Only Mode

vim -R file.txt

🟣 Basic Vim Commands You MUST Know

💾 Save and Quit

:w → save :q → quit :wq → save + quit :q! → quit without saving

🧽 Delete Commands

x → delete one character dw → delete one word dd → delete whole line 3dd → delete 3 lines

📋 Copy-Paste (Yank & Put)

yy → copy line 3yy → copy 3 lines p → paste after cursor P → paste before cursor

🚀 Move Around Faster

h → left j → down k → up l → right

⚡ Jump Commands

gg → go to start of file G → go to end of file 0 → go to beginning of line $ → go to end of line

🔍 Search in Vim

▶ Search a Word

/word

Press n to jump to next result
Press N to previous result


♻ Replace Text in Vim

Replace First Occurrence

:s/old/new/

Replace in Entire File

:%s/old/new/g

Example

Replace http with https in a config file:

:%s/http/https/g

🧩 Real Examples (Useful for SysAdmins & Developers)

✔ Example 1: Edit SSH Config

vim /etc/ssh/sshd_config

Search:

/Port

Change port:

i → edit → :wq

✔ Example 2: Comment/Uncomment Lines

Comment:

I# (Insert # at start)

Uncomment:

^x (delete #)

✔ Example 3: Copy 10 lines and paste

10yy p

🧠 Advanced Vim Features (Must Learn)

🔸 Visual Mode

Select text like a pro.

Enter Visual Mode:

v → character selection V → line selection Ctrl+v → block selection

🔸 Undo / Redo

u → undo Ctrl + r → redo

🔸 Split Windows (Multi-file editing)

:split filename :vsplit filename

Move between windows:

Ctrl + w + w

📊 Comparison: Vim vs Nano vs GUI Editors

FeatureVimNanoVS Code
Terminal-based
Fast & Lightweight
Learning CurveHardEasyMedium
Powerful Editing✔✔✔✔✔
Ideal ForAdmins, DevOps, CodersBeginnersDevelopers

🏁 Conclusion: Is Vim Worth Learning?

Absolutely YES.
Vim looks difficult at first, but once you master it:

✔ You edit files faster
✔ No need for mouse
✔ Perfect for SSH, servers, DevOps
✔ Highly customizable
✔ Saves HOURS every week

Vim is a skill every Linux admin must know — and now you have the complete guide to use it like a pro. 🚀

Previous Post Next Post

نموذج الاتصال

Telegram