sponsor Vim development Vim logo Vim Book Ad

June 2022

Vim 9.0 released

After many years of gradual improvement Vim now takes a big step with a major release. Besides many small additions the spotlight is on a new incarnation of the Vim script language: Vim9 script.

The previous release was version 8.2 in December 2019. Since the latest source code is always available on GitHub, many have already picked up later patch versions (there are more than 5000 of them!). Therefore the changes have already been tried out by many users. On top of that bugs have been fixed, security issues have been addressed, and many tests have been added. Code coverage has been dramatically increased. This version is more reliable than any before.

Why Vim9 Script

A new script language, what is that needed for? Vim script has been growing over time, while preserving backwards compatibility. That means bad choices from the past often can't be changed and compatibility with Vi restricts possible solutions. Execution is quite slow, each line is parsed every time it is executed.

The main goal of Vim9 script is to drastically improve performance. This is accomplished by compiling commands into instructions that can be efficiently executed. An increase in execution speed of 10 to 100 times can be expected.

A secondary goal is to avoid Vim-specific constructs and get closer to commonly used programming languages, such as JavaScript, TypeScript and Java.

The performance improvements can only be achieved by not being 100% backwards compatible. For example, making function arguments available by creating an "a:" dictionary involves quite a lot of overhead. In a Vim9 function this dictionary is not available. Other differences are more subtle, such as how errors are handled.

For those with a large collection of legacy scripts: Not to worry! They will keep working as before. There are no plans to drop support for legacy script. No drama like with the deprecation of Python 2.

Interesting Features

To profit from the speedup a function must be defined with def. The argument and return types must be specified. This is not only to make execution faster, it also helps uncovering mistakes early, when the function is compiled into byte code. Variables are declared with var and also have a type, either explicitly or inferred from the assigned value.

Line continuation does not require using a backslash, the mechanism that is used in legacy script, which is a bit weird and was required to keep it backwards compatible.

Function calls do not require call, assignments are done without let and expressions are evaluated without eval. This makes a Vim9 script look a lot more like most programming languages.

Splitting up a large script in small pieces has been made a lot simpler. In one script export is used to make specific functions and variables available to other scripts. The rest is local to the script. Then import is used where the exported items are to be used. Combined with an autoload mechanism this makes a flexible and powerful way to implement large plugins.

Comments now start with #. The previous double quote syntax, which comes from the good old Vi, interferes with how strings are used. The use of # is known from many other languages, such as Python and shell scripts.

Otherwise most things work the same way. Users who have written Vim script will find it easy to switch over. Unexpected differences usually lead to an error message with a hint how to do make the line work in Vim9 script.

Details about Vim9 script and rationale for the choices can be found here or with :help vim9 in Vim.

Otherwise, many improvements were made not related to Vim9 script. You can find a list here or with :help new-9 in Vim.

Future Work

There will surely be a Vim 9.1 release. Nobody knows when.

Among the plans for Vim9 script is the addition of classes. Although a dictionary can be used to simulate this, it is far from ideal. Most programmers are familiar with classes such as Java has. Something like that should be added to Vim9 script. The keywords are already reserved.

About Vim

Vim is a highly configurable text editor built to make creating and changing any kind of text very efficient. It is included as "vi" with most UNIX systems and with Apple's macOS.

Much of Vim was written by Bram Moolenaar ([email protected]). Many, many others have helped making Vim what it is now by adding features, fixing bugs, suggesting improvements, etc.

Vim is Charityware. You can use and copy it as much as you like, but you are encouraged to make a donation for needy children in Uganda. Please visit the ICCF web site for more information: https://iccf-holland.org

TOP

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github