I am wondering if it is just a matter of taste or if there is any benefit in using some of the new features in Vim9.

I am interested in interpolated-strings and the autoload mechanism.


var name = "John"
var age = 23

# Which form is better?
echo "My name is " .. name .. " and I am " .. age .. "years old." # 'legacy'
echo $"My name is {name} and I am {age} years old." # 'new'


I can use either

command -nargs=1 SomeCommand bar#MyFunc(<f-args>) # 'legacy',


import autoload "../lib/foo.vim" as bar # 'new'
command -nargs=1 SomeCommand bar.MyFunc(<f-args>) # 'new' 

Is it just a matter of taste, or there are specific benefits in using the 'new' forms over the 'legacy' ones?

1 Answer 1


As a scant answer, :help vim9script:

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.

In summary:

  • "modern" syntax (for some value of modern)
  • types
  • compiled bytecode
  • breaks compatibility concerns

All of which is aimed at better performance (except the syntax).

  • Ok, does that traduces in that interpolated-strings and “new way” of using autoload is faster? What I can immediately see is aesthetic (which is better for the new interpolated string, but for the autoload is too verbose and more error prone in my opinion) but about e.g. performance?
    – Barzi2001
    Commented Apr 14, 2023 at 13:31
  • @Barzi2001 frankly I'm not sure if interpolated strings are faster than string concatenation or not. Myself I often use printf(). The new autoload mechanism is the same as the old one, just for using vim9script; so, loading a function that way probably isn't too different. But executing a function will be, at least if you call it more than once! The first time, the function is compiled and then executed. Subsequent calls only execute the compiled function.
    – D. Ben Knoble
    Commented Apr 14, 2023 at 17:43
  • I will say that repeated string-concatenation is likely to suffer from en.wikipedia.org/wiki/…, assuming it is left-associative.
    – D. Ben Knoble
    Commented Apr 14, 2023 at 17:45
  • 1
    @D.BenKnoble In vim9, when facing a series of concatenations, apparently, the byte code compiler is able to optimize (the memory allocations anyway) by first calculating the total size. github.com/vim/vim/commit/…
    – Mass
    Commented Apr 15, 2023 at 1:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.