| Contents |

36 Appendix: Just Enough Vim

Vim64 is a very-commonly installed editor with a steep learning curve.

This appendix is here just to give you enough Vim to be dangerous!

36.1 Launching Vim

It could be you found yourself in Vim because you were committing and you didn’t use -m to specify a message. You’ll know it if you see some ~ characters down the left and some kind of status bar at the bottom.

Or you might have launched it yourself with something like this, to edit foo.c:

$ vim foo.c

Vim primarily exists in two modes:

The power of Vim comes from memorizing tons of Normal Mode commands. This allows you to move the cursor and edit at speed. The vimhelp website has a reference of all the normal mode commands65, just to give you a rough idea of what’s available.

But at first, when you barely know any Normal Mode commands, modal editing just seems to get in the way. But as you get better at it, you’ll see it’s actually a really powerful feature.

36.3 Going Between Modes

Here are the two main modes:

There! You’ve learned one normal mode command! i to insert some text!

Try it: launch Vim, type i, then type hello world!, then hit ESC to get back to normal mode.

36.4 Moving the Cursor

You can probably use the cursor keys. In fact, your version of Vim might even allow you to use them without ever leaving insert mode.

Real Vim users move the cursor in normal mode with the following keys.

Muscle memory will eventually take over with these.

If you’re in insert mode, the delete key should generally work as expected, as well.

36.5 More Modes

I said there were two main modes, but there are actually more. Here are two more bonus modes:

36.6 Command Line Mode

As mentioned earlier, if you’re in normal mode, you can hit : to get to command line mode.

This moves the cursor to the bottom of the screen and allows you to type a command there.

So from now on in this chapter, when I say something like :q!, that means to type those three characters from normal mode.

If you get into command line mode and want to get back to normal mode, just press return without entering a command.

36.7 Exiting Vim

There are a few ways, and all of them start from normal mode. (So hit ESC after you’re done entering text, then try to exit.)

And one more that’s of use for Git:

If you do a :cq when entering a commit message in Vim, Git will think something went wrong and not complete the commit. So if you find yourself in Vim writing a commit message and think, “I didn’t mean to do this yet!” you can :cq to get out of it. The files will remain on the stage.

36.8 Learn More

If you have Vim installed, you already have Vim Tutor installed! This is just a file that gets opened and directs you through using and learning vim.

Launch it with:

$ vimtutor

If you don’t feel like messing with it right now, you can just :q! to quit.

There’s also an interactive online tutorial called OpenVim66 that gets you through the first steps.

Finally, ChatGPT67 or other AIs will be helpful in finding new normal mode commands and answering questions.

“This your last chance. After this there is no turning back. You take the blue pill, the story ends. You wake up using your normal editor and edit files whatever way you want to. You take the red pill, you stay in Vim and I show you how deep the rabbit hole goes.”

                          —With apologies to Morpheus, The Matrix


| Contents |