4 MINUTE READ | March 28, 2012
A Very Brief Introduction to Vim
Vim is not your traditional text editor. Folks my age are very relient on computer mice, and we’re used to removing our hands from the keyboard to click around and get to where we want to go. Vim is a different sort of editor in the respect that all the work is done form the keyboard. In fact, if you’re good at it, your fingers almost never have to leave home row.
The big challenge to using Vim is stated right on it’s about page: Vim is a tool. It’s not going to hold your hand or come built in with defaults. It’s configurable, and you’ll have to learn to use it.
If you’re on a Mac, you already have vim. Just open up terminal, type vim, and hit enter. If you’re on windows, or would like a full color GUI version of Vim, you’ll need to head to the download page to get it.
Vim has three modes: normal, insert, and visual. Visual mode is outside the scope of this introduction. When you open up a text editor, you can usually start typing right away. Vim is different, you start in normal, or command, mode – you can’t actually enter any text yet. To get to insert mode, you must hit the i key. After switching to insert, you can type away.
To get back to normal mode, simply hit the escape key. Alternatively, you can use control+[ to return to normal mode.
Remember when I said above that, if you’re good with Vim, your fingers rarely have to leave home row? Before we move on, enter some text in vim: From the command line type vim and hit enter. Once inside the program, hit “i” to enter insert mode and type away.
All done? Hit escape to return to normal mode. Now move around the text with the h, j, k, and l keys. Typing “h” will move your cursor left. “l” will move it right. “k” will move the cursor up a line; “j” will move it down.
Movement goes beyond just one character at a time. Easily move around words with ^, b, B, e, and E keys: ^ (shift + 6) takes you to the beginning of a line, b and B will move you to the beginning of the previous (or current) word, and e and E will take you to the end of the next word.
In addition to moving around, you can also use normal mode to enter commands. All vim commands are prefaced with a colon (:).
What to delete an entire line? In normal mode type :d and hit enter. Line gone! Whoops, did you mess up? Hit the “u” key to undo.
You can jump to any line in file by typing :_n_ where n is the line number. Copy a line of text with :y – “y” stands for “yank”. To place copied text, hit the “p” key to place it below the line with cursor or shift+p to place it above the current line.
The real strength of vim is that it’s highly configurable. The .vimrc is where that happens. Placed in your home directory on unix-like systems (OSX and Linux distros), you’ll never find this file in Finder – files starting with a dot don’t get viewed there.
.vimrc configurations are a bit outside the scope of this article, but suffice it to say that everything in vim is configurable all the way down to the keyboard shortcuts. The best way to learn? Head over to github and do a search for “dotfiles”. Repos that you find will likely contain other folk’s vimrc’s. Take a look, if you see an option that looks interesting, head back over to Vim, enter the normal mode, and type :h theoption to see what it’s all about.
github — Looking at other people’s configs is a great way to learn!
Stay in touch
Subscribe to our newsletter
AlliPMG CultureCampaigns & Client WorkCompany NewsDigital MarketingData & Technology
4 MINUTES READ | November 2, 2021
2 MINUTES READ | February 4, 2020