What is Vim?

Vim is a Unix text editor that's included in Linux, BSD, and macOS. It's known for being fast and efficient, in part because it's a small application that can run in a terminal (although it also has a graphical interface), but mostly because it can be controlled entirely with the keyboard with no need for menus or a mouse. For instance, to insert text into a file, you press I and type. To navigate or to issue a command (such as Save, Backspace, Home, End, and so on), you press Esc on your keyboard and then press whatever key or key combination corresponds with the action you want to take. It's a very different way of editing text compared to what modern computer users expect, but it's the way Unix admins all over the world edit config files, changelogs, scripts, and more.

Vim is also commonly referred to as Vi because when it was written by Bill Joy in the late 1970s, it was short for visual editor. Before Vi, few people even imagined that a computer could act as a sort of interactive typewriter. Text files were edited with commands (like ed) that would find a specific line and either insert or remove text; literally all text was manipulated with what amounted to a rudimentary version of your favorite office application's find-and-replace menu (but without the office application). Vi was a breath of fresh air, enabling users to enter a screen session that showed them their entire file and allowed them to edit it live.

[Download our Vim cheat sheet]

While many people claim to love and use Vi, few people use Vi over Vim on a daily basis. In casual conversation, Vi and Vim are interchangeable and usually refer to Vim (Vi Improved). On some POSIX systems, the vi command is a pointer to Vim (or else Vim is just called Vi). However, some systems ship just with Vi and you have to install Vim separately.

To verify whether you have Vim installed, use this command:

which vim

If you get nothing in return, you don't have Vim installed. Install Vim from the project's homepage.

Furthermore, some distributions offer a few different builds of Vim. Usually, this means there's a minimal build that mimics the old Vi, with just enough Vim-isms included to make it usable, and an enhanced build that offers a truly modern Vim experience. The best way to determine what's available is to search your package manager for any package containing the string "vim" and then install the one with the most features (like vim-enhanced on Fedora).

Why use Vim?

Vim is the default fallback editor on all POSIX systems. Whether you've just installed the operating system, or you've booted into a minimal environment to repair a system, or you're unable to access any other editor, Vim is sure to be available. While you can swap out other small editors, such as GNU Nano or Jove, on your system, it's Vim that's all but guaranteed to be on every other system in the world.

Its efficiency in both design and function is hard to ignore, too. Vim's native terminal-based interface doesn't rely upon menus or fancy peripherals or even "extra" keys like Ctrl or Alt. Vim (mostly) uses keys common to any keyboard, regardless of language, layout, or device (and those that aren't common can be remapped pretty easily).

Vim on mobile devices

If you run a terminal on your mobile phone, Vim is a great choice for editing except for one problem: You probably don't have an Esc key. While there are alternate keyboards available for download, they often add extra keys at the expense of key size. If that's not a change you're willing to make, then you can set Vim to map Esc to some other key sequence. Add this imap command to your environment's .vimrc (this example uses two commas as the escape sequence, but you can use anything that you don't anticipate usually typing in quick succession, like qq or yy):

imap ,, <Esc>

How to use Vim

There's no illusion that Vim is intuitive, so its developers have created vimtutor, a simple, interactive walkthrough of the basics. Although Vim is bursting with potential, there are only a few controls you need to know in order to use it. Paraphrasing vimtutor's first lesson, here are the essentials:

  • Start Vim from a terminal by typing vim or on your desktop by launching gvim.
  • Press I to enter insert text mode. When in insert mode, all you can do is type text into your document. There are no commands in insert mode.
  • Press Esc to enter normal mode, used for commands.
  • In normal mode, you can move your cursor with h (left), j (down), k (up), and l (right). It might help to remember that j is down by equating it, visually, with a Down arrow.
  • To exit Vim, type :wq if you want to save your work or :q! to discard unsaved changes.

Beyond these basics, all other Vim commands are arguably for convenience and efficiency.

Vim with Afterglow theme

When you first launch Vim, you create and open a temporary and empty text file, just as you would when opening any other text editor. Unlike other text editors, however, you can't type anything into the file at first. That's because you're in normal mode, which is used to issue commands to Vim. It expects that your first action will be opening a file or saving an empty one as something with a sensible name. If your intent is to type without opening a file or saving your current one, enter insert mode by pressing I on your keyboard. After entering this mode, you can enter text as you'd expect.

Using Vim is a constant dance between insert and normal modes, but once you're used to it, it becomes so fluid that you don't think about it. It's a little like pressing the Caps Lock key (instead of Shift) to get a series of capital letters or like a press-and-hold on a mobile keyboard to get an alternate character. We don't call these actions "modes," but that's what they are: they're toggles that you flip on or off to change the context of some action. For instance, when you want to move back a word in Vim, you press (and then release) Esc to enter normal mode and then b to move your cursor to the left one word. It's different from other text editors, but if you think about it, the concept of changing modes isn't foreign.

Vim plugins

Vim is extensible, meaning that you can add features to it through plugins. With a history spanning decades, Vim has are plenty of useful plugins to choose from and even entire sites, like Vim Awesome, dedicated to Vim plugins.

You can install plugins manually or with a Vim package manager like Vim-plug. If you're a casual Vim user, you can easily become dependent upon Vim through plugins. From simple color schemes to file managers, plugins are Vim's way of keeping you coming back for more.

Become a Vim pro

Getting good at Vim takes some practice, and for the first week or so, it'll feel like someone secretly rearranged the keys on your keyboard (and stole your mouse). However, working through vimtutor helps get you started with a solid foundation, and our Vim cheatsheet goes a long way to relieve the stress of remembering important commands. In no time, you'll find yourself using Vim as second nature, and eventually, you'll catch yourself absent-mindedly hitting Esc in all your favorite applications.

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.