This website uses cookies to ensure you get the best possible experience. See our Cookies Policy.

PMG Digital Made for Humans

A Very Brief Introduction to Vim

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.

Insights meet inbox

Sign up for weekly articles & resources.


Posted by Christopher Davis

Related Content

thumbnail image

Get Informed

PMG Innovation Challenge Inspires New Alli Technology Solutions

4 MINUTES READ | November 2, 2021

Get Informed

Applying Function Options to Domain Entities in Go

11 MINUTES READ | October 21, 2019

thumbnail image

Get Informed

My Experience Teaching Through Jupyter Notebooks

4 MINUTES READ | September 21, 2019

Get Informed

Trading Symfony’s Form Component for Data Transfer Objects

8 MINUTES READ | September 3, 2019

Get Inspired

Working with an Automation Mindset

5 MINUTES READ | August 22, 2019

Get Informed

Parsing Redshift Logs to Understand Data Usage

7 MINUTES READ | May 6, 2019

Get Inspired

3 Tips for Showing Value in the Tech You Build

5 MINUTES READ | April 24, 2019

thumbnail image

Get Informed

Testing React

13 MINUTES READ | March 12, 2019

Get Inspired

Tips for Designing & Testing Software Without a UX Specialist

4 MINUTES READ | March 6, 2019

Get Informed

A Beginner’s Experience with Terraform

4 MINUTES READ | December 20, 2018

ALL POSTS