Skip to content
Snell Rojas

Programming

Vim Basics Tutorial

A basic tutorial with the minimum commands you need to know to use Vim as your terminal text editor.

Snell RojasPublished Updated 3 min read

I wrote this post in Spanish in 2022 and adapted it to English in 2026.

This is a short tutorial on the most basic Vim commands. It's not advanced. It's so you know how to get around, and from here you can dig in on your own and become a Vim Jedi.

Basic Vim (Vi IMproved) Commands #

Create a file

bash
$ vim file_name.extension

# Example:

$ vim random.py

By default you can't type; you move around with:

text
J: up
K: down
H: right
L: left

If you want to type, you have to enter -- INSERT -- mode, and you do that by pressing i.

Leave -- INSERT -- mode

Press the Esc key.

Quit the editor

Vim
:q

Save and quit

Vim
:wq

To skip any questions, add a ! at the end, for example to quit the editor:

Vim
:wq!

Show line numbers

Vim
:set nu

Hide line numbers:

Vim
:set nu!

Cut a line

Vim
dd

Paste a cut line

Vim
p

Copy a line

Vim
yy

Create a new line

Vim
o

(The letter o. It automatically enters -- INSERT -- mode.)

Cut several lines

Vim
d[number]d
d3d

(d3d cuts 3 lines in a row.)

Copy several lines

Vim
y[number]y
y3y

(y3y copies 3 lines in a row.)

Undo a change

Vim
u
uuu

(uuu undoes the last 3 changes.)

Redo an undone change

Ctrl + r

Enter visual mode in Vim

Vim
v

Search for text in the file in Vim

Vim
/text

Then press Enter. It takes you to the first match; to go to the next one press n, and to go to the previous one press Shift + n.

Go to the start of the file in Vim

Vim
gg

Go to the end of the file in Vim

Shift + g

Go to the start of the line in Vim

0 (zero) or the Home key.

Go to the end of the line in Vim

$ or the End key.

Save a file with whatever name you like in Vim

Vim
:w foo.txt

This creates a file named foo with the .txt extension.

If you save a file that already existed under a different name, Vim will create a new "copy" file if you didn't change anything, and a "new" one if you made changes.

Indent multiple lines in Vim

text
:start_line,end_line>

where:
- start_line is the first line
- end_line is the last line
- > is the number of indents

example:

1 text
2 text
3 text
4 text
5 text

:2,3>>

Result:

1 text
2         text
3         text
4 text
5 text

Open a folder with Vim

bash
$ vim /path_to_folder/

$ vim .   # opens the current folder

Go back to the folder after opening a file

Vim
:#b