DEV Community

Cover image for VI/VIM in Linux: The Ultimate Terminal Text Editor
SAHIL
SAHIL

Posted on

VI/VIM in Linux: The Ultimate Terminal Text Editor

If you’re diving into the world of Linux, DevOps, or Cloud, you can’t avoid VIM.

🔹What is vi/vim?

VI = Visual Editor (original UNIX editor)
VIM = Vi IMproved — a more powerful version

🟢 It’s lightweight, fast, and works great even on minimal systems. It edits files in a small buffer and gives you full control over whether to save or discard changes.

📂 How to Open a File in Vim

Open your terminal and then type command by replacing filename with your file.
vim (filename/absolute_file_path)
ex: vim testfile1
🧾 This opens the file in Normal mode (the default mode).

🔸 Modes in vim (most confusing part for beginners)

🧭 Mode ⚙️ Use Case
Normal Mode Navigate, delete, copy, paste
Insert Mode Type or insert text
Visual Mode Select text for copying/cutting
Command Mode Save, quit, search, etc.

➡️ Switching between modes:

By default the file opens in default mode, in order to write in file we have to press the i key to enter insert mode. To exit insert mode press Esc key and to enter command mode we have to press ' : ' colon key.

🔑 Key Press 🔄 Mode Entered
i Insert Mode
Esc Back to Normal
: Command Mode

Note: To enter every mode , first we have to press Esc to exit other. Make this a habit to press Esc and then enter other modes.

💾 Saving and Quitting in Vim:

Once you're done editing:

Press Escto go to Normal mode.

Type : to enter Command mode.

Use one of the commands below:

💻 Command 📝 Description
:q Quit (only if no changes made)
:w Save changes
:wq Save and quit
:q! Quit without saving changes (force)

🛑 ! means forcefully — use with caution!

🧪 Demo Time — Try It Yourself 💻

Just go to your home-directory in terminal and run this command:
vim myfile
This will create a new-file named myfile and will open it in vim. If you already have a file you can just put your filename instead of myfile.

Now by default you can view the file content and do other operations that are advance level.
To enter insert mode just press i. Now you can edit the file content.

After you are done with editing just press Esc to exit insert mode and then press : colon to enter command mode.Now you can see a colon on the bottom of your terminal. Now just type wq and press enter. Your file will be saved and you will exit the vim.

If you want to exit the vim and wish not to save the changes just type q!. You can keep saving changes using w without exiting the vim. If you have not made any changes and want to exit the vim just go to command mode and press q and then enter it.

To open the file again, just type vim myfile

Here are steps:

  • Open using vim filename
  • Press i → enter Insert mode and type something
  • Press Esc → return to Normal mode
  • Press : → enter Command mode
  • Type wq → save and quit

👉 Other useful commands:

:q! → Quit without saving

:w → Save (but stay in Vim)

:q → Quit (only if nothing changed)

Note: Once you enter command mode you don't have to put extra colon in front of command like w,q. These are just character commands.

📣 Let’s Learn Together!
💬 Feel free to correct me or drop your own Vim tips in the comments!
I’ll be posting an advanced Vim guide soon — with time-saving shortcuts in Normal mode.
Thank You.

Top comments (0)