SHARE
Facebook X Pinterest WhatsApp

Absolutely Essential Vim/vi Commands

Written By
thumbnail Joe Brockmeier
Joe Brockmeier
Nov 1, 2010
ServerWatch content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More



More on Vim

So you thought you could get by with gedit? Not when you must configure an application on your server in a data center two states away! When it comes to remote system administration, all roads lead back to Vim. Not a Vim expert? No problem, you just need a handful of commands to do everything you need to do.

When it comes to remote system administration, all roads lead to Vim. While Vim’s capabilities are vast — entire books have been written about it, and they still fail to capture all of its functionality — knowing a handful of commands will enable you to do much of what you need to do.

Entire books have been written about Vim, and they still fail to capture all of its functionality. But the core command set is all you really need if you’re just making a few changes to a few files over SSH. You might not do it as efficiently as a Vim expert, but it’s good enough to get the job done. In fact, if you’re working with Vim (the pre-eminent vi-clone) on a server, there’s a good chance it’s “vim-tiny,” a stripped-down Vim that offers the traditional vi functionality but not the full set of Vim features.

Insert Mode

The first thing you must grok is that Vim has several modes — command mode, insert mode, and last-line mode (also known as ex mode). When you start Vim, you’ll be in command mode. Here, all of the keys are used to perform commands, not input text. To switch to input mode, hit i, and you’re able start editing the file, adding text, using Backspace, etc.

To return to command mode, hit Esc. To enter last-line or Ex mode, use :, and then input the command you wish to enter.

Vim Command Mode

I could go on for days about the commands needed in command mode, but we’re just here for the basics, so let’s look at movement. Movement is based on the standard alphabetic keys:

  • h Move the cursor to the left one character.
  • l Move the cursor to the right one character.
  • j Move the cursor down one line.
  • k Move the cursor up one line.

You can move faster by using b and w to move backward and forward by one “word” at a time, respectively. Vim looks at “words” as a string of alphanumeric characters. So “word” is a word, but “one-year” is multi-word because it’s broken up by a non-alphanumeric character.

Deleting is done with d or x. To delete a single character, move the cursor over that character and use x. Using dw will delete the word the cursor is over, and db will delete the previous word.

To delete an entire line, use dd. To delete from the cursor to the end of the line, use d$. To delete from the cursor to the beginning of the line, use d0. The $ is shorthand for “end of the line,” and 0 is shorthand for beginning of the line. You can also use ^.

Copying and Pasting in Vim

Let’s look at copying and pasting real quick. To highlight text to copy, use the v, V and Ctrl-V commands. You might have guessed by now that Vim commands are case-sensitive, So v and V are different things.

The v command simply allows you to highlight changes character by character using the movement (hljk and others) or arrow keys. The v command highlights entire lines. And the Ctrl-v command highlights blocks of text — very useful for highlighting and copying columns of text.

Once you’ve highlighted the text you want to copy, hit y to “yank” the text into the buffer.

To paste the text, use p or P to paste. The p command will paste after the cursor, and P pastes before the cursor.

Page 2: More Absolutely Essential Vim/vi Commands

thumbnail Joe Brockmeier

Joe Brockmeier is the editorial director of the Red Hat Blog. He joined Red Hat in 2013 as part of the Open Source and Standards (OSAS) group, now the Open Source Program Office (OSPO). Prior to Red Hat, Brockmeier worked for Citrix on the Apache OpenStack project, and was the first OpenSUSE community manager for Novell between 2008-2010. Brockmeier also has an extensive history in the tech press and publishing, having been editor-in-chief of Linux Magazine, editorial director of Linux.com, and a contributor to LWN.net, ZDNet, UnixReview.com, and many others.

Recommended for you...

What Is a Container? Understanding Containerization
What Is a Print Server? | How It Works and What It Does
Nisar Ahmad
Dec 8, 2023
6 Best Linux Virtualization Software for 2024
What Is a Network Policy Server (NPS)? | Essential Guide
ServerWatch Logo

ServerWatch is a top resource on servers. Explore the latest news, reviews and guides for server administrators now.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.