Learn Vim: Unlock the Power of Fast and Efficient Text Editing in the Terminal

Vim is fast, powerful, lightweight, and built into almost every UNIX-based system. Whether you're editing config files over SSH or writing code at speed, Vim gives you complete control. No mouse, no lag, just pure efficiency.

It may feel strange at first, but the best way to learn Vim is by diving in and doing simple, useful exercises. In this guide, you'll learn the basics: how to create, write, quit, and navigate your way around files.

Ready? Open your terminal and let's get started.

Why Use It #

Vim stands for "Vi IMproved". It’s an enhanced version of the classic Unix text editor vi, with more features, flexibility, and power for efficient text editing.

Most people start with nano because it’s simple. But nano can’t:

  • Quickly select and move blocks of text
  • Jump to a function or keyword in seconds
  • Search and edit across multiple lines with ease
  • Highlight syntax for code, config files, and markup by default

Vim can. And once you get a feel for it, you won’t want to go back.

It’s preinstalled on most systems, lightning fast, and entirely keyboard-driven. Once you master a few commands, editing becomes effortless, powerful, and even enjoyable.

Installation #

Debian/Ubuntu Linux:

bash
sudo apt install vim -y

macOS (with Homebrew):

bash
brew install vim

Windows (with Chocolatey):

bash
choco install vim

Vim's Modes #

Vim isn’t like most editors. It uses modes, and each mode gives your keys a different purpose.

Mode What It Does Enter with Exit with
Normal Move, delete, copy, paste, undo Esc -
Insert Type like a normal editor i Esc
Visual Select text (character, line, block) v, V, Ctrl+v Esc
Command Save, quit, search : Enter
Replace Type over existing text R Esc

Getting Started #

The best way to learn is by doing.

Step 1: Open Vim and Create a File #

First, let us create a new file and open it in Vim.

In your terminal, type:

bash
vim file.txt

You will see a mostly blank screen with some information at the bottom. Congratulations, you are inside Vim!

Step 2: Insert Mode #

By default, Vim opens in normal mode. In this mode, you can navigate and run commands, but you cannot type text directly.

To start writing, you need to switch to insert mode. Press:

text
i

You should now see -- INSERT -- at the bottom of the screen. You can now type freely, just like in any other text editor.

Try typing a few lines:

text
Hello, Vim!
This is my first file.
Learning by doing is fun.

Step 3: Save Your File #

After writing, you want to save your work. First, you must leave insert mode.

Press:

text
Esc

You are back in normal mode. Now, to save the file, type:

text
:w

and press Enter. w stands for "write", it saves the file.

You should see a message at the bottom like:

text
"file.txt" written

Step 4: Quit Vim #

Now that your file is saved, let’s exit Vim.

In normal mode, type:

text
:q

and press Enter. q stands for "quit".

If you have unsaved changes and you try to quit, Vim will warn you. You can force quit without saving by typing:

text
:q!

To save and quit in a single command, type:

text
:wq

Step 5: Manipulate Text #

Let’s explore some basic editing and text manipulation.

Reopen the file:

bash
vim file.txt

To select all text in the file, press:

text
ggVG

Here’s what happens:

  • gg moves the cursor to the beginning of the file.
  • V starts visual line mode.
  • G moves to the end of the file, selecting everything.

To copy the selection to the clipboard, press:

Press Shift + ' then y.

text
"+y

To delete all highlighted text, press:

text
d

To delete a line, place the cursor on it and press:

text
dd

To undo the last change, press:

text
u

To redo the last change, press:

text
Ctrl + r

To paste the clipboard after the cursor, press:

text
p

Step 6: Search and Replace #

To search for a word or pattern in the file, type:

text
/<pattern>

Then press Enter. Vim will jump to the first match.

  • Press n to go to the next match.
  • Press N to go to the previous match.

To replace all occurrences of the word old with new:

text
:%s/old/new/g

To replace with confirmation for each match:

text
:%s/old/new/gc

Step 7: Move Around Quickly #

A few more quick tips to move efficiently:

  • hjkl move left, down, up, right.
  • 0 moves to the beginning of the line.
  • $ moves to the end of the line.
  • gg jumps to the top of the file.
  • G jumps to the bottom of the file.

Master these and you will fly through your files.

Essential Commands #

These commands will get you started editing like a pro in Vim:

Command Description
Save and quit :w Save
:q Quit
:qa Quit (all)
:wq Save and quit
:q! Quit without saving
Select mode i Insert mode
v Visual mode (character selection)
V Visual mode (line selection)
Esc Return to default mode
Navigate Move
gg Go to start of file
G End of file
0 Go to start of line
Shift $ Go to end of line
Edit u Undo last change
Ctrl R Redo last change
o Insert new line below
O Insert new line above
dd Delete current line
dw Delete current word
d Shift $ Delete from cursor to end of line
d a p Delete paragraph
c i ' Delete all text inside ''
c i Shift ' Delete all text inside ""
yy Copy current line
p Paste after cursor
P Paste before cursor
Edit (visual mode) d Delete
y Copy selection
Shift ' + y Copy selection to clipboard
gg V G Select all text and copy to clipboard
= Auto-indent
> < Indent / unindent
Search and replace /<pattern> Search
n Go to next match
N Go to previous match
:%s/old/new/g Replace all occurrences of old with new
:%s/old/new/gc Replace with confirmation for each occurrence

Next Steps #

Learning Vim is like learning to ride a bike: awkward at first, but smooth and fast once you get going. With a few practical exercises, you’ve already seen how powerful and surprisingly easy it can be.

Keep going. Open Vim every day, even for quick notes or edits. The more you use it, the more natural it becomes. Before long, your fingers will fly and Vim will feel like second nature.