Vim, an Open-Source Text Editor
Total Page:16
File Type:pdf, Size:1020Kb
Vim, an open-source text editor by Bram Moolenaar The main author of the open-source text editor Vim writes about how it came to be and how it is being developed. The Charityware concept is discussed and why Bram chose to use it for Vim. Diving into the data structures and functions to manipulate them, he gives you some idea of how this complex program works. Some of the new features that Bram has added in Vim 6.0 are discussed. Introduction There is a small chance you have never heard about Vim. It is included with almost every Linux distribution as the standard Vi editor. For many systems such as FreeBSD and Sun Solaris 8 it comes as an extra package you can easily install. For other systems (MS-Windows, Macintosh, OS/2, etc.) executables and source code can be downloaded from many places on the internet. Vim is a text editor like Vi, but with many extra features; of the Vi-like editors Vim has often been voted the best - in fact the main competition comes from Emacs, in all its different versions. In 1999 Emacs was selected the winner in the Linuxworld text editing category, with Vim second, but in February 2000 Vim won the Slashdot Beanie award for best open source text editor pushing Emacs into second place. So these editors are in the same league. One of the main advantages of Vim (and Vi) is that the most often used commands are typed with alphabetic characters. This is much faster than using Control or Meta key combinations, and less stressful on the fingers. The extra time it takes to learn the commands is soon repaid by allowing you to work efficiently. However Vim, unlike Vi, also supports the use of cursor keys in Insert mode and so a beginner can get started quickly before gradually learning more commands to gain speed. Compared to other Vi-like editors Vim has very many features: syntax highlighting for over 180 languages, automatic indenting for C code, a powerful script language, etc. There is something for everyone. The development of Vim is ongoing. At the moment of writing, the work for Vim version 6.0 has finished in September; more about that further on. The main goal for Vim is to be a very stable and useful tool; besides adding more features, improving the existing features and fixing bugs is pursued very actively. Compare that to the original Vi, for which not much work has been done since 1985. This picture shows the GTK version of Vim, editing C source code with syntax highlighting. The search pattern "msg_didany" is highlighted with a yellow background. There is a Visual selection (grey background) with a green, blinking cursor. At the bottom "-- VISUAL --" indicates the current mode and at the right the position in the file is shown. History of Vim A long time ago I got myself an Amiga computer. Since I was used to editing with Vi, I looked around for a program like Vi for the Amiga. I did find a few so-called 'clones', but none of them was good enough; so I took the best one, and started improving it. At first the main goal was to be able to do all that Vi could do. Gradually I added some additional features, like multi-level undo. When it was working reasonably well, I released a version of Vim (then called "Vi IMitation") on a public domain disk set for the Amiga, made by Fred Fish. Then others started sending me patches. A few people took the effort to port Vim to other platforms, like MS-DOS and Unix. I added more features and made it work better. By that time it was justified to rename it to "Vi IMproved". Over time the code has been redesigned and extended so much that almost nothing of the original 'clone' remains. When I started working on Vim it was just for my own use. After some time I got the impression it was useful for others, and sent it out into the world. Since then I'm working more and more on making the program work well for a large audience. It's fun to create something useful. Also, there is a nice group of co-authors and power users, which is very inspiring. Here is an overview of Vim's history: ------------------------------------------------------------------------- 1991 Nov 2 - Vim 1.14: First release (on Fred Fish disk #591). 1992 - Vim 1.22: Port to Unix. Vim now competes with Vi. 1994 Aug 12 - Vim 3.0: Support for multiple buffers and windows. 1996 May 29 - Vim 4.0: Graphical User Interface (largely by Robert Webb). 1998 Feb 19 - Vim 5.0: Syntax coloring/highlighting. 2001 Sep 26 - Vim 6.0: folding, plugins, vertical split ------------------------------------------------------------------------- What does IMproved stand for? By version 1.22 Vim included more features than Vi. I decided to change the name from "Vi IMitation" to "Vi IMproved". Over time the gap has grown wider, now it's hard to think of a reason to use Vi instead of Vim. I would recommend all Vi users to switch to Vim. The list of advantages is very long, here are just a few: - Unlimited line length and allow NUL bytes: Possibility to edit any file, including binary files. - Multi-level undo and redo: Don't worry about destroying your file when caps-lock was accidentally on. - Multiple windows and buffers: Edit several files at the same time, copy text between them. - Syntax highlighting: Quickly understand the structure of the text and spot errors. - Command line history and completion: Correct typos, recall old commands, quickly enter long file names. - Delete and put rectangular text areas: Edit a table. - Error message parsing: Run the compiler and immediately jump to locations where errors have been found. - On-line help with hyperlinks: Find comprehensive documentation for any command and jump to related subjects. - A powerful script language: Add your own extensions. Developing Vim After a couple of years of hard work version 6.0 is now finished. I have done the core items myself, but many people join in. Sometimes they create a new feature and send me a patch that I can include right away, but mostly the patches I receive need to be integrated into the current version. Few people can overview how all the parts of Vim work together, since the code has become quite complex. For example, someone created a patch for multi-line search patterns. This showed how it could be done, and the locations in the sources that had to be changed. Unfortunately the author used pointers to text lines, and didn't realise that these can become invalid. I had to go through all the new code to fix this. Although that was a lot of work, the patch I got helped me by setting me on the right track. Users ask questions on the Vim mailing lists, which indicates to me what the most common problems are. Sometimes people send me patches or requests for new features. I think that this co-operation of users and co-developers is the main strength of how Vim is being developed. Users and developers communicate directly with each other and with an open spirit. This is how open source software can grow to become better than commercial software. Distribution Vim can be distributed freely; however, there are some modest restrictions. This is the text that comes with Vim: ------------------------------------------------------------------------- SUMMARY Vim is Charityware. You can use and copy it as much as you like, but you are encouraged to make a donation to orphans in Uganda. See |iccf| below. If you include Vim on a CD-ROM, I would like to receive a copy. Just so I know which Vim distributions exists in the world (and to show off to my friends :-)). DETAILS There are no restrictions on distributing an unmodified copy of Vim. Parts of Vim may also be distributed, but this text must always be included. You are allowed to include executables that you made from the unmodified Vim sources, your own usage examples and Vim scripts. If you distribute a modified version of Vim, you are encouraged to send the maintainer a copy, including the source code. Or make it available to the maintainer through ftp; let him know where it can be found. If the number of changes is small (e.g., a modified Makefile) e-mailing the diffs will do. When the maintainer asks for it (in any way) you must make your changes, including source code, available to him. The maintainer reserves the right to include any changes in the official version of Vim. This is negotiable. You are not allowed to distribute a modified version of Vim when you are not willing to make the source code available to the maintainer. The current maintainer is Bram Moolenaar . If this changes, it will be announced in appropriate places (most likely www.vim.org and comp.editors). When it is completely impossible to contact the maintainer, the obligation to send him modified source code is dropped. It is not allowed to remove these restrictions from the distribution of the Vim sources or parts of it. These restrictions may also be used for previous Vim releases instead of the text that was included with it. ------------------------------------------------------------------------- I prefer to give users much freedom in using the Vim source code. The main reason to add restrictions is to avoid what happened to Elvis some time ago: someone took the Elvis source code, added a few nice Windows GUI things, and started selling it.