Hacking Vim 7.2

5 (1 reviews total)
By Kim Schulz
    Advance your knowledge in tech with a Packt subscription

  • Instant online access to over 7,500+ books and videos
  • Constantly updated with 100+ new titles each month
  • Breadth and depth in over 1,000+ technologies

About this book

Vim is one of the most powerful open-source editors used by programmers and system administrators around the world. While Vim itself is inherently a powerful editor, personalizing it to suit your needs can be a daunting task. However, it is possible to do so with the help of this book.

This book contains examples that cover everything from personalizing Vim according to the your work cycle to optimizations that will boost the your productivity. The main focus of this book is to make your life, as a Vim user, easier.

Each chapter deals with a different aspect, and provides recipes for easy-to-use hacks to customize and simplify your Vim experience. After an introduction covering the derivation of Vim and its relatives from the vi editor, the author explains basic changes that you can make to the appearance of the Vim editor. Further chapters cover improved navigation through files and buffers in Vim; speeding up your work with templates, auto-completion, folding, sessions, and registers; and formatting text and code, including using external formatting scripts. The final comprehensive chapter covers everything about using Vim scripts and scripting to extend functionality.

This book is written for Vim 7.2, the latest stable version. This latest version of Vim includes many new features like spell-checking, code completion, document tabs, current line and column highlighting, undo branches, and much more.

Publication date:
April 2010


Chapter 1. Getting Started with Vim

The Vim editor (or Vi IMproved) was first released by Bram Moolenaar in November 1991 as a clone of the Unix vi editor for the Amiga platform.

The first release of Vim for the Unix platform was out a year later, and it started to become an alternative to the vi editor right away.

The combination of a more liberal licensing model, and the fact that Vim started to become a superset of vi's functionality resulted in it becoming progressively more popular with the open source community. Soon more and more Linux distributions started adopting Vim as an alternative to vi. Even if the users thought they used vi (if they actually executed the vi command), they opened Vim (the vi command had simply been substituted with a link to the vim command, which has often led to the misunderstanding that vi and Vim are actually the same program).

During the late 90s, Vim took over where vi was lacking behind in the so-called editor war that existed between the vi editor and the Emacs editor. Bram implemented a lot of the missing features that the Emacs community used as arguments for why Emacs was better than vi / Vim, but he did it without ever neglecting the main focus areas that the vi editor had right from the beginning.

Today, Vim is a feature-rich, fully configurable editor, loved by many. It supports syntax-highlighting of more than 200 different programming languages, autocompletion for a fast growing number of languages, folding, undo / redo, multiple buffers / windows / tabs, and a lot of other features.

In this chapter, we will take a look at the following items:

  • How to get and install the vim editor

  • The vim family of editors

  • The license that vim is released under

  • Common terminology used throughout the book

So, let's get started with this book.


Getting Vim

You might already be familiar with the Vim editor and have used it for a long time. If, however, you haven't played around with Vim yet, this is the right time to get a copy and install it on your system.

You will always be able to get the latest version of the Vim editor from the project web page at:



This book primarily focuses on Vim version 7.2, but don't worry if you have an older version—you can always upgrade your installation if you find that you need it.

On computers running Microsoft Windows, you simply run the downloaded .exe file and it will then take you through the installation. After installation, a shortcut to gVim will be available in the start menu.

On computers running Linux, the installation depends on the Linux distribution you are using. Chances are that you already have Vim installed as it comes pre-installed on most distributions today. If it is not already installed, then refer to the distributions package manager (for example Aptitude in debian, urpmi in Mandriva, and Synaptics in Ubuntu) to see how to install Vim. If no package manager is available, you can always install Vim from the source you downloaded using the previously mentioned link. See the readme file for information on the exact commands to use in order to install it.


vi, Vim, and friends

Vim is just one of many derivatives of the original vi that Bill Joy released back in 1976. Some have a feature list very close to that of vi, while others have chosen to add a wide variety of new features. Vim belongs to the group of vi clones that has chosen to add extra features. In the next section, we will introduce some of the better-known clones of vi and briefly describe the distinct features that each clone has.


vi is the original root of the Vim family tree. It was created by Bill Joy in 1976 for one of the earlier versions of Berkeley Software Distribution (BSD). The editor was an extension of the most common editor at that time, ex. Ex was, in turn, an extension of the Unix editor ed. The name "vi" is actually an abbreviation of visual in ex. As the name indicates, vi was actually just a command that started the ex editor in one of its modes—the visual mode.

vi was one of the first editors to introduce the concept of modality. What this means is that the editor has different modes for different tasks—one mode for editing text, another for selecting text, and yet another for executing commands.

This modality is one of the main features in vi, which makes enthusiasts like the editor, but it is also what makes others dislike it even more.

Not much has changed in vi since the first version, but it is still one of the most used editors in the Unix community. This is mainly because vi is considered a required application for Unix to comply with the Single Unix Specification (SUS)—and hereby be able to call itself a Unix.


In 1987, Tim Thompson got his first Atari ST (Sixteen / Thirty-two). In this platform, there weren't any really good editors and so, he decided to clone the vi editor, which was known from the Unix platform. In June 1987, he released an editor under a license that resembles what has later become known as open source. He released it on Usenet and named it STEVIE—an abbreviation for ST Editor for VI Enthusiasts.

It was very simple and provided only a very small subset of the functionality that vi provided. It did, however, provide a familiar environment for vi users moving to the ST.

After the release, Tim Thompson discontinued work on the editor. But soon Tony Andrews took over, and within a year he had ported it to Unix and OS/2. More features were added along the way, but at some point around 1990, the development stopped.

STEVIE as an editor might not have survived throughout the years, but since both Tim and Tony released the source code on Usenet as public-domain for anyone to use, a lot of the later vi clones have been both inspired and based on this code.


STEVIE was one of the more common editors around. It was, however, full of bugs and had some quite impractical limitations. Steve Kirkendall, who at that time used the operating system Minix, noticed one very big limitation, that is, the STEVIE editor held the entire file in memory while editing. This was not an optimal solution when using Minix, so Steve decided to rewrite the editor to use a file as buffer instead of editing in RAM. This turned into Elvis, version 1.0.

Even though Elvis was an improvement over the vi editor, it still suffered from some of the same limitations that vi had—maximum length of lines and only a single file buffer.

Steve Kirkendall decided to rewrite Elvis completely to get rid of the limitations, and this turned into Elvis version 2, which is the generation of the editor currently available (version 2.2).

With generation 2 of Elvis, Steve also included support for a range of other features that weren't in the original vi editor. Among these, a few features that are interesting and worth mentioning are:

  • Syntax highlighting

  • Multiple windows support

  • Networking support (HTTP and FTP)

  • Simple GUI frontends

Elvis is not actively developed anymore, but is still widely used. It is available for Unix, MS Windows (console or GUI with WinElvis), and OS/2.


The latest version of the Elvis editor can always be found here at



nvi, or new vi (as its full name is), is a result of a license dispute between AT&T and the Computer Science Research Group (CSRG) at University of California, Berkeley. vi was based on an original code from the ed editor, which was under the AT&T System V Unix license, so it was not possible for CSRG to distribute vi with BSD.

CSRG decided to replace the vi editor with an alternative editor under a freer license—their own BSD license.

Keith Bostic was the man that took on the job to make the new vi. The vi clone Elvis was already freely available, but Keith wanted an editor that resembled the original vi editor even more. He took the code for Elvis and transformed it into an almost 100 percent vi compatible clone—the nvi editor. Only the Open Mode and the lisp edit option from the original vi functionality set is left out.

By the release of 4.4BSD, the vi editor was completely substituted by nvi, and the software distribution was once again completely covered by a free license.

Today nvi is the default vi editor in most BSD-derived distributions such as NetBSD, FreeBSD, and OpenBSD, and has evolved into a more feature-rich editor than the original vi.

Compared to the original vi editor, nvi has been extended to support new features such as:

  • Multiple edit buffers

  • Unlimited undo

  • Extended regular expressions

  • CScope support

  • Primitive scripting support in Perl and Tcl / Tk

Keith Bostic is still the maintainer of the nvi source code, but not much development has been done to the code for some time now.


The latest version of the nvi editor can always be found here at



The Vim editor is the golden child of the vi family. Ever since Bram Moolenaar released the first version of Vim to the public in November 1991, this editor has evolved into one of the most feature-rich editors around.

The first version of Vim was, like the Elvis editor, based on the source code of the STEVIE editor. Bram, however, released Vim only for the Amiga platform, which was one of the most widespread platforms, at that time, among home computer enthusiasts. At that time Vim was an abbreviation for Vi IMitation, which described Vim quite well, in that it simply tried to do what vi did.

However, a year later in 1992, Bram made a port of his Vim editor for the Unix platform. The result of this was that Vim went beyond simply being a clone of vi for a different platform, to becoming a competitor. The development of Vim was quick and fast, and soon Vim had a range of features that the original vi editor did not have. Because of this, the abbreviation Vim was at some point changed into being Vi IMproved instead of Vi IMitation.

Within a couple of years, Vim grew to having a range of features that a lot of vi users missed. This made more and more users switch over to using Vim instead of vi as their primary editor.

In 1998, the fifth generation of Vim was released, and with it one of the most used features of today, scripting, was introduced.

Now, it was possible for the user to write their own scripts for Vim, and in that way expand the functionality of the editor. This was a really strong addition to the feature set of Vim because it would normally have required coding in a lower-level language, and recompilation of the editor in order to add even simple features.

A lot of features have been added to Vim throughout the last decade, and many of these are quite unique compared to the other editors and vi clones in particular.

Here, we will list just a few of the more distinct features of Vim, as the complete feature list would be too long:

  • Editing multiple files in multiple buffers, windows, and tabs

  • Advanced scripting language

  • Support for scripting in Perl and Python

  • Syntax highlighting for more than 200 programming languages

  • Unlimited undo / redo with branching

  • Context-aware completion of words and functions

  • Advanced pattern-matching with regular expressions

  • Close integration with a wide range of compilers, interpreters, and debuggers

  • More than 1500 Vim scripts freely available online

Vim is available for an enormous variety of platforms such as all types of Unix, Linux, MS Dos, MS Windows, AmigaOS, Atari MiNT, OS/2, OS/390, MacOS, OpenVMS, RISC OS, and QNX.


Vile maybe the vi clone that looks least like the original vi editor—some would even say that it's not a clone at all. Vile is actually an attempt to bring the best of two worlds together in one editor—the modality of vi and the feature set of Emacs.

This also explains the name Vile, which is the shortform for VI Like Emacs.

The Vile editor project was started by Paul Fox during the summer of 1990. The code was based on the core code from the public-domain editor, MicroEmacs. Paul then modified it to have modality and other vi-like features.

The MicroEmacs code did not have all the features of the Emacs editor, but it had support for long lines and editing multiple files in multiple windows at the same time. These were features that vi did not have and which many programmers needed in their editor.

A lot of work was done to get the MicroEmacs code to be more vi-like, and several other developers joined the project. Thomas E. Dickey joined the project in 1992 and added a wide variety of features to Vile and fixed a lot of bugs in the code.

In 1994, Kevin Buettner joined the project and started working on the GUI version of vile—xvile . He added support for some of the most common widget sets at that time, such as Athena, OpenLook, Motif, and the Xt Toolkit.

Today, Thomas is the primary maintainer of Vile and the development is steered by him. His time for working on the editor is, however, very limited. So, it is mostly only bugfixes that he adds to the editor.

Vi and Vile are not very similar in the way they work, and only a minor subset of the vi features are present in Vile. The main features of Vile are:

  • Editing modes—one mode for each file type

  • Vile procedure language for macros

  • (Experimental) Perl support

  • Named functions that can be bound to keys as the user wishes

Vile is available for Unix, Linux, BeOS, OS/2, VMS, and MS Windows and exists in both a console version and a GUI version.


The latest version of the vile editor can always be found here at http://invisible-island.net/vile/vile.html.


Though all the vi clones have at some point tried to behave like the vi editor, most of them have evolved in very different directions. This means, even though a lot of them support features such as syntax highlighting, they do not necessarily implement them in the same way. Therefore, a syntax file from Vim cannot be used in Elvis.

Even the features that originate from vi are not necessarily implemented the same way. Some of the clones have implemented features less accurately than others. Maybe the idea behind the feature is the same, but the actual result of using it is completely different.

In the following table, I have tried to give a percentage of how accurately the mentioned clones resemble the vi editor (0 percent being least compatible and 100 percent being completely compatible). The comparison has been done by looking at how much effort the clone developers have made in order to implement the features of vi as precisely as possible.


vi compatibility




Only a very small feature set in common.



Only general concepts such as modes in common.



Large feature set in common, some features behave quite differently though.



Nearly perfect compatibility, but a range of the features behave differently.



In the "compatible mode", nearly all features are compatible.

In the table, only the features that the clones share with vi are considered. This means, even though, for example, Vim has a lot of features that vi does not have, it still resembles vi very precisely on the features that they share. Besides this, Vim implements nearly all of the features that vi has. Only some of the features that Bram Moolenaar considered as bugs in vi are implemented differently in Vim. Note that in order to make Vim 99 percent compatible with vi, you will have to set it into compatible mode with the command:

:set compatible


In Vim you can read more about vi and Vim differences with the command:

:help vi-differences

Another interesting observation is that even though STEVIE implemented a subset of the vi functionality very accurately, it did not implement enough of the vi features to be considered a close relative.


Vim is charityware

Bram Moolenaar, the developer of the Vim editor, has chosen to release Vim under a so called charityware license. What this means is that you can copy Vim as much as you like, but in exchange you are encouraged to make donations to a charity.

You can read more about the project if you open Vim and execute the command:

:help uganda

You can also get more information about how you can sponsor the Vim project if you go to the website http://www.vim.org/sponsor/.

As a Vim sponsor, you will get to vote for new features that should be implemented in Vim. So, besides supporting a good cause, you will also get some say on how Vim will evolve in the future.


Common terminology

Some words tend to have a different meaning depending on who you ask, hence, we have made a short list of some of the words here:

  • Hacker: A technology interested person that likes to explore tech-related things and optimize them to fit his and others' needs.

  • Hacking: The process a hacker goes through when exploring and optimizing his software or hardware. "Hacking Vim" would hence refer to the process of optimizing the Vim editor to fit the hacker's (user's) needs.

  • Script: A textual program consisting of one or more lines of code that runs in an interpreter. A script can be written in many different programming languages, but will have to use one that matches the interpreter.

  • Interpreter: A program that reads lines in a script and executes them one by one. An interpreter can be built into another program such as the Vim editor.



In this chapter, we introduced Vim and looked at what this book is about. Vim is just one of many clones of the old Unix vi editor, so, to get a broader view of the vi family tree, this chapter introduced some of the more well-known clones. Their history and relation to vi were briefly described and we learned that even though the vi clones at some point have tried to be like vi, they are not really compatible with each other.

We looked a bit at the concept of charityware, and how the author of the Vim editor uses that to raise money for children in need in Uganda. Finally, we took a look at some of the terminology used in this book and why the book is called "Hacking Vim".

You are now ready to go on with the next chapter and learn about how to personalize your Vim editor.

About the Author

  • Kim Schulz

    Kim Schulz has an M.Sc. in Software Engineering from Aalborg University in Denmark. He has been an active developer in the Linux and Open Source communities since 1997 and has worked with everything from translation and bug fixing to producing full-blown software systems. This entire time, Vim has been Kim's editor of choice and it has been the first thing he installs whenever he sits by a new computer. Today Kim works as a full-time software engineer at CSR Plc. developing software for the next generation wireless technologies. A lot of Kim's spare time has been spent on developing the open-source CMS Fundanemt. This has lead to him now owning the web-hosting company Devteam Denmark that specializes in hosting and development of Fundanemt-based websites.

    Browse publications by this author

Latest Reviews

(1 reviews total)
Amazing and easy to use book
Hacking Vim 7.2
Unlock this book and the full library for $5 a month*
Start now