How to Get Good with Vim

Vim has a lot of strong qualities going for it, that make it a good choice to learn no matter who you are.

First of all, it's on everything. If you have a virtual server, it takes 1 second to install. It always works, every time, without needing customizations or anything.

Second of all, it's fast. No editor is faster to load than Vim, and because it's so stripped down, it never hiccups.

Third, it's good to know because if you're on someone else's server, it's probably the fastest thing you can open.

Fourth, I sometimes like to use vim because it's concept of "modes" (see below) makes it very hard to accidentally modify a file. If I'm in a config file, I often want to be very sure I'm not dropping in a stray apostrophe somewhere. Vim gives you confidence that you're only editing the file when you want to, no exceptions.

About the Jokes

can't exit vim

A common joke.

Vim isn't very intuitive to learn.

You're basically dropped in the editor, and counterintuitively, the usual ways you use to move around every other editor suddenly don't work.

Vim has 'modes'. The idea is that, when you're doing one thing, you should be in one mode, and when you want to do something else, it's time to switch to a different mode.

When you start, you're in normal mode, which lets you navigate through a file, but not modify it.

"Insert mode" is generally the mode newbies are trying to access. You can access it by typing the letter "i". You can exit it by typing the Escape key. (In general, hit Escape when you're lost in Vim and looking for an answer).

Also, read the modeline at the bottom of the screen. That will often tell you "type :q to quit." Many times it'll answer your question.

Sometimes you can get really stuck, if you accidentally mashed the wrong combination of buttons. The modeline can help you here; read what it says and google how to exit. This has happened to me once or twice before (even with years of experience), so don't feel bad if you need to resort to this option.

The Basics

Here are the basics, which you can get really, really fast at, with some practice.

Open a file with vim from the command line like this:

vim file.txt

Navigate around like this:

Press "l" to go right on a line.

Press "j" to go down a line.

Press "k" to go up a line.

Press "h" to go left on a line.

If you want to do one of the above multiple times, prefix the command with a number. I'll sometimes type "100j" if I want to go to the middle of a file (or "2000j" if I just want to not think about it and jump to the bottom).

Press "i" to be able to enter file insert mode. Make any changes you want, and press "Esc" to exit.

Press "A" to append at the end of a line, and press "O" to insert a line before your line and put there cursor there.

Press "x" to delete the character the cursor is currently over.

Press "dd" to delete a line. There are different permutations of "d" with another letter - example, "dw" to delete a word - which you can move on to next.

Type "/" and then the text you want to search for, when you're searching for text in a file. (Personally, I use this a lot.)

Press ":w" to write your changes to file.

Press ":q" to exit the file, ":q!" to exit it without saving any changes, and ":wq" to write and exit with no further questions.

You will want to refer to a cheatsheet, and start remembering the keystrokes, to become really proficient.

vim basics Devhints.io has a good one, though there are many others you can use.

Keep Learning

And that's how you do basic Vim-ing!

If your file has a common extension - say, .js - Vim will often recognize it and do syntax highlighting on its own.

If you need extra functionality, you can look into plugins, of which Vim has many.

Finally, remember that with Vim, the more you use it, the faster you get. So, use Vim a lot to get really fast with it. That's when Vim becomes a joy to use, in my experience.