Bare Minimum Vim Tutorial for Beginners

A beginner's guide to Vim tutorial

Hey there! Some links on this page may be affiliate links which means that, if you choose to make a purchase, I may earn a small commission at no extra cost to you. I greatly appreciate your support!

After spending five minutes with this Vim tutorial, you’ll walk away with the basic knowledge to edit text files using only your keyboard.

There are a few simple commands that you must remember in order to use Vim. To keep this tutorial as simple as possible, you’ll learn these commands only and nothing more.

Let’s get right into the tutorial.

How to Use Vim

Let’s says there’s a file that we want to edit called test.txt (right click and Save Link As to download this file and follow along).

To open this file with Vim, simple issue the following command in Terminal or your command prompt.

vim test.txt

This will open the Vim text editor program.
Terminal window with an example text file with 4 lines

Using Insert Mode to Edit a File

Let’s make a couple changes to this file. First, let’s add your name to the third line. To do this, we must first enter insert mode. To enter insert mode, simple hit the i key on your keyboard. Notice how the lower left corner of your window now says -- INSERT -- which means you’re in insert mode.

Vim insert mode

Now you can use your arrow keys to move the cursor down the third line and over to the period. Type your name here. Notice how although the cursor is on the period, the text is inserted before the period.

Example showing how to type text in Vim insert mode

Lastly, let’s remove the last line in the file. Move the cursor down one line and all the way to the right with your arrow keys. This time, make sure the cursor goes to the right of the period.

Screenshot of the cursor in Vim insert mode at the end of a line of text

Now you can simply use the backspace key on your keyboard to remove each character in this line. Make sure you hit the backspace key one last time to move the cursor up to the end of the third line to completely eliminate the last line.

Arrow pointing to Vim cursor at end of line

How to Save a File in Vim

Now that we are satisfied with our changes, we will want to save them. To save a file in Vim, we must first get out of insert mode by hitting the Esc key. Notice how the -- INSERT -- indication goes away.

Leaving insert mode in Vim

Next, let’s enter command line mode by typing : like this. Notice how a color appears in the bottom left corner of your window.

Vim command line mode indicated by a colon in the lower left corner

Here we have a few options. We can either save the file, save the file and exit Vim, or discard our changes and exit Vim. Here’s how you can accomplish each.

  • :w save your file without exiting Vim
  • :wq save your file and exit Vim
  • :q! don’t save your file and exit Vim

We will want to save the file and exit Vim so type :wq and hit enter to execute this command.

Save file and exit Vim in command line mode

Basic Vim Commands Summary

There are essentially two modes that you must know in order to use Vim at a basic level.

  1. Insert Mode to edit a file. You can access insert mode with i
  2. Command Line Mode to save a file and exit VIM. You can access command line mode with :

If you get confused as to which mode you’re in, you can always hit the Esc key to leave whatever mode you’re currently in.

When you are in insert mode, you can freely use you keyboard arrow keys to move around the file and type text as you normally would in a word processor.

When you are in command line mode, your three basic options are to:

    1. Save your file without exiting Vim with :w
    2. Save your file and exit Vim with :wq
    3. Discard changes and exit Vim with :q!

If you can remember these simple commands and keyboard shortcuts, you will be able to edit any file from the command line with Vim.

YouTube video

Facebook
Twitter
Pinterest
LinkedIn
Reddit

Meet Tony

Tony from Tony Teaches Tech headshot

With a strong software engineering background, Tony is determined to demystify the web. Discover why Tony quit his job to pursue this mission. You can join the Tony Teaches Tech community here.

2 Responses

Leave a Reply

Your email address will not be published. Required fields are marked *