Vim9script

See also Vimscript, which is the original language predating Vim 9.


Example

This is a convoluted example, making use of a command that is also compatible with traditional Vimscript, but nonetheless works.

The Vim9script interpretter only begins to run after the vim9script command is seen within a script.

vim9script
:echo "Hello, world!"


Breaking Changes

Furthermore, in order to break code across lines in traditional Vimscript, backslashes were often necessary. Vim9script does not have the same requirement.

Functions are now compiled. The compilation occurs in the background of a vim(1) session, and may raise errors.


Variables and Constants

var count = 0
count += 3

final matches = []                # add to the list later
const names = ['Betty', 'Peter']  # cannot be changed


Functions

Vim9script tries to compile functions lazily. Compilation is triggered by:

To forward reference a function that is not defined yet, try:

def MyFunc()
  execute('DefinedLater')
enddef


CategoryRicottone

Vim/9Script (last edited 2023-01-12 15:55:51 by DominicRicottone)