Default value of function parameter in Vim script

From the docs, it seems that arguments can’t have default values in Vim script. However, you can emulate this by defining a function with variable number of arguments, and using a:0 to determine the number of extra arguments and a:1 through a:n to access them:

function Foo(bar, ...)
  if a:0 > 0
    let xyzzy = a:1
    let xyzzy = 0

Leave a Comment