Getting Started With Vim
This is a brief guide to get you acquainted with using Vim in the terminal. If
you’re reading this, you’ve probably heard of Vim already. For those that
haven’t, it’s a text-editor that’s a bit different than most. It’s optimized for
touch typists, and eschews the use of a mouse in favor of keyboard shortcuts.
Rather than binding controls to modifiers such as the
Alt keys, Vim
makes use of different editing modes. When you’re just navigating your
code base, you’re in
NORMAL MODE.When you want to type in text, you go into
INSERT MODE. This talk of modes might not make sense just yet, but read on,
and you will see the light.
I won’t lie to you, Vim has a steep learning curve. It can be intimidating at first, even daunting. In the beginning, you will feel sluggish, wondering why it’s so difficult to do basic things. You will be confused. You may even be frightened. It’ll take some time, but the rewards will prove to be worth it in the end.
Get What You Need
The first step on your journey is to get Vim on your machine. If you’re running Linux or OSX, chances are that you already have it. Windows users can grab it here, or run it under some equivalent of Cygwin.
If you’re on Ubuntu, Vim is there, but it’s sort of hidden away under the guise of Vi. You can improve your experience by installing a package that has Vim compiled with some nicer flags. This should set you straight:
sudo apt-get install vim-gtk
If you’re on a Mac, then you have Vim, but it’s probably a little dated and missing some cool features. If you don’t already have Brew, you’ll want to grab that here and install it. Once you’ve done that, open up a terminal and type in this command:
brew install macvim --override-system-vim
Both of these install instructions also get you GUI versions of Vim. They can be a bit nicer in terms of appearance, but you lose out on the flexibility of being in a terminal if you choose to go with them.
You can only get so much out of reading guides and blogposts. Now that you have Vim installed, it’s time to take the plunge. Open up a terminal, and type in:
This will launch an interactive guide. I know it says that it should take about 30 minutes to go through it, but don’t be afraid to take longer if you need it. Go through it completely before coming back to this guide.
Improve Your Understanding
Having gone through
vimtutor, you should have some familiarity with Vim. It’s
perfectly normal to not remember most things. Below, you’ll find a quick
cheatsheet of the more useful commands in normal mode. Wherever you see a
<CR>, take that to mean “Hit the Enter/Return key”. It stands for “carriage
return” if you were curious. Oh, and remember that escape will take you back
into Normal mode.
:q<CR> quit :q!<CR> quit without saving :w<CR> save u undo Ctrl r redo i go into Insert mode at the cursor a go into after the cursor
The best way to get better in Vim is to keep programming. These basic commands should be enough to get you started. If you have to stop and look up how to do something every now and then, it’s fine.
Part of the reason why Vim is so well-loved is because of how customizable it
is. Linux and OSX users can save these settings in a file called
is located in their home folders. Windows folks can use
to help them find where there vimrc should go.
Customizing vim is a rather advanced topic, and I won’t cover much here. However, certain Vim defaults absolutely suck. The only way to go about fixing them is to actually change them. Welcome to the Wonderful World of Vimscript.
Below here, I have a simple
.vimrc file that I like to give out to people just
getting started with Vim. Feel free to take it and run with it. It’s pretty well
commented, so this should be enough to get you started.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
I’ll probably write more about Vim in the future, but there are plenty of other resources around if you’re interested in learning more. There’s no substitute for actual experience though.