Vim 10 minutes crash course

Saksham Jain
3 min readFeb 24, 2023

--

Vim Crash Course

It is imperative that you have a least a beginner primer in how to use vim in order to be able to do your job confidently and effectively. Here’s a 10 minute crash course.

What is vim?

Vim is short for “visual modified.” Vim is a bare bones but extremely powerful text editor that you run in your terminal. You can (and will!) use it to make quick changes to files without having to open them in a separate application.

How do I open a file using vim?

In your terminal, type the command vim <file name>

How do I close a file that I’ve opened in vim?

This is one of the most upvoted questions ever asked on StackOverflow. To close vim:

  1. Make sure you aren’t in INSERT mode by hitting the esc key
  2. Type the colon character :
  3. To save your changes, type w for write
  4. To quit the application, type q for quit
  5. Hit enter for the command to take effect

I speak this out loud as “escape colon write quit” — esc :wq

How do I edit a file in vim?

The most basic way to edit a file in vim is to type i to enter INSERT mode. Now you can type in the file. If that’s as far as you get in this tutorial for now, that’s fine.

To exit INSERT mode, hit esc

What are the next five vim commands I should learn?

Vim commands can only be typed when you are not in INSERT mode. If you are in INSERT mode, vim will tell you this by putting the word INSERT at the bottom of the screen. To exit INSERT mode, hit esc

Here are some commands I use all the time:

  • 0 - moves you to the beginning of the line that the cursor is on
  • $ - moves you to the end of the line that the cursor is on
  • dd - deletes the entire line that the cursor is on
  • dw - deletes the word that the cursor is on
  • p - pastes whatever you just deleted using the dd or dw command

Honestly, that’s enough for now. Everything else you can just do by using the arrow keys to move around. When you get frustrated by that eventually because it’s too slow, pick five new commands you want to learn and memorize them.

Where can I find more help in learning vim?

Linux.com has a nice 101 post on more basic vim commands.

How can I practice this right now?

  • Make a new file (touch practice to make an empty file called practice)
  • Open the file (vim practice)
  • Type some text into the file (remember to type i first to enter INSERT mode!)
  • Hit enter and type more things on the next line! Make five lines of random text. (When I’m learning and I need random text, I write nice things to myself. You should do the same. Here are some ideas: “I am smart. I can do this. I will be successful. Nobody will stop me. I have the right and the ability to learn anything I want to learn.”)
  • Now that you have several lines of text, hit esc to exit INSERT mode
  • Try going to the beginning and end of a line (0 for beginning! $ for end!)
  • Try deleting an entire line (dd)
  • Try pasting that line back (p)
  • Save the file without closing (:w)
  • Save the file and close it (:wq)

You are smart. You can do this. Nobody can stop you. You have the right and the ability to learn anything you want to learn.

--

--

Saksham Jain
Saksham Jain

Written by Saksham Jain

I am Software Engineer working at Amazon who has passion for DataScience, ML, Stock Market, Crypto Market, Blockchain

No responses yet