DaleSchool

Meeting Vim for the First Time

Beginner15min

Learning Objectives

  • Explain what Vim is and why you should learn it
  • Open a file with the vim command
  • Switch between Normal mode and Insert mode
  • Save and exit with :wq

Working Code

Open your terminal and follow along:

vim hello.txt

The screen changes and Vim opens. Don't type anything yet! You're in Normal mode.

Press i. You'll see -- INSERT -- at the bottom of the screen. Now you can write:

Hello, Vim!
This is my first file.

When you're done typing, press Esc. -- INSERT -- disappears and you're back in Normal mode.

Now it's time to save and exit. Type :wq and press Enter:

:wq

You're back in the terminal! Let's check that the file was saved:

cat hello.txt

Output:

Hello, Vim!
This is my first file.

Congratulations! You just created, edited, saved, and exited a file with Vim.

Try It Yourself

Open the file again:

vim hello.txt

Press i to enter Insert mode, then add any sentence on a third line. Then press Esc:wq to save and exit.

This time, let's exit without saving:

vim hello.txt

Press i, type anything, then press Esc and enter :q!:

:q!

Run cat hello.txt to check. What you just typed is gone. :q! means discard changes and quit.

"Why?" — Why Learn Vim?

When you SSH into a server to edit a config file, there's often no GUI editor:

ssh production-server
# VS Code? Not installed
# Mouse? Not available
# All you have is Vim
vim /etc/nginx/nginx.conf

Vim is installed by default on almost every Unix/Linux system. You'll meet it naturally when managing servers, working inside Docker containers, editing Git commit messages, and more.

I can't exit Vim! (the famous meme)

"How to exit Vim" is a legendary Stack Overflow question with millions of views. Everyone hits this wall once. Don't panic!

Escape hatches:

CommandMeaning
:wqSave and quit (write + quit)
:qQuit (only if no changes)
:q!Force quit without saving
:wSave only (stay in Vim)
ZZSame as :wq (uppercase Z twice)

The key is to press Esc first. No matter what mode you're in, Esc brings you back to Normal mode — and from there you can type commands starting with :.

vimtutor — the official practice program

Vim comes with a built-in tutorial called vimtutor:

vimtutor

About 30 minutes of hands-on practice opens right inside Vim. Running it alongside this course helps the keys settle into your fingers faster.

Deep Dive

  1. Create a new file with vim practice.txt.
  2. Press i to enter Insert mode and type three of your favorite foods, one per line.
  3. Press Esc:wq to save and exit.
  4. Run cat practice.txt to check the contents.
  5. Open the file again with vim practice.txt, add a line, then exit with :q!. When you run cat, the added line should be gone.
  6. Try running vimtutor in your terminal (optional).

Quiz

Which key do you press to start typing text in Vim?

You made changes by mistake. How do you discard them and quit?

How do you return to Normal mode from Insert mode?