How to Edit Files in Linux Using Nano and Vim (Beginner Guide)

Published On: September 24, 2025
Follow Us
Edit Files in Linux Using Nano and Vim

Editing Files in Linux with Nano and Vim :In Linux, graphical text editors like Gedit or VS Code are great — but when you’re working in the terminal, especially on servers, you’ll need to know how to use command-line text editors like Nano and Vim.

This beginner-friendly guide will teach you:

  • What Nano and Vim are
  • How to open, edit, save, and exit files
  • Key commands and shortcuts
  • Which editor is best for you

📄 What Are Nano and Vim?

Both are pre-installed on most Linux systems and run entirely from the terminal.


🧸 Editing Files with linux Nano (Beginner-Friendly)

✅ Opening a File with Nano

nano filename.txt
  • If the file exists, it opens it.
  • If not, it creates a new one.

✏️ Editing in Nano

Just start typing — Nano works like a basic text editor.


💾 Saving Your Changes

  1. Press Ctrl + O to write out (save).
  2. Press Enter to confirm the file name.

❌ Exiting Nano

  • Press Ctrl + X to exit.
  • If you made changes, Nano will ask if you want to save.

🧠 Nano Shortcut Cheatsheet


⚙️ Editing Files with Vim (The Power Tool)

Vim has a learning curve because it works in modes:

  • Normal Mode – Navigate and run commands
  • Insert Mode – Type and edit text
  • Command Mode – Save, quit, etc.

✅ Opening a File with Vim

vim filename.txt

✏️ Start Editing in Vim

  1. Press i to enter Insert Mode
  2. Type your text as needed

💾 Saving & Exiting Vim

  1. Press Esc to return to Normal Mode
  2. Type one of the following and press Enter:

🧠 Vim Mode Cheatsheet


🆚 Nano vs Vim: Which Should You Use?

💡 Tip: Start with Nano. When you’re comfortable with the terminal, level up to Vim — it’s worth it.


👨‍💻 Examples of When to Use These Editors

  • Nano:
    • Editing config files: nano /etc/hostname
    • Writing a quick script: nano hello.sh
  • Vim:
    • Power editing on remote servers
    • Editing large files with advanced navigation

🧠 Pro Tips

  • Use sudo if editing system files: sudo nano /etc/hosts sudo vim /etc/fstab
  • Try vimtutor in the terminal to learn Vim interactively.
  • If Vim feels too hard, try Neovim or Micro editor for modern alternatives.

🔚 Conclusion

Knowing how to edit files in the terminal is a must-have Linux skill. Whether you choose the simplicity of Nano or the powerful features of Vim, mastering a command-line editor will make you faster, more efficient, and more capable — especially when working on remote servers or system administration tasks.

Start small, practice often, and soon the terminal will feel like second nature.

sapan singh

👨‍💻 About Sapan Singh Hi, I’m Sapan Singh — a passionate software developer with a strong love for technology, gaming, and building useful digital tools.

Join WhatsApp

Join Now

Join Telegram

Join Now

1 thought on “How to Edit Files in Linux Using Nano and Vim (Beginner Guide)”

Leave a Comment