For example this function signature has several braces [ and ]:

matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])

What it means? Unnecessary argument?

1 Answer 1


Yes, you've got it. It's an optional argument.

func(foo [, bar])

Can be called as

func(foo, bar)



In the latter case the function will usually have some predetermined value assigned to bar (usually noted in the function's documentation.) Or it might ignore it altogether.

Nested square brackets indicate that an optional parameter inside of another can't be supplied unless the outer one is as well.

func(foo [, bar [, baz]])


func(foo, bar, baz)


func(foo, bar)


func(foo, baz)

With cases like the last some caution is in order. If bar and baz are defined as having the same value "type" (e.g. the function expects numbers for both) then the call could still go through even though you, for example, may have just mistakenly forgotten to include bar. The ultimate result of mistakes like this could be anything from a loud, immediate failure to some subtly flawed behavior that occurs only after a delay. The latter type of problems are often very hard to diagnose so proceed carefully.

On the other hand, if bar is supposed to have one type (say, an integer) and baz is supposed to be an instance of another type (e.g. a string) then the fault is easier to detect. Note, though that in an interpreted, dynamically typed language like Vimscript code may have to be added explicitly to identify such problems. (Versus a compiled, statically typed language where the function signature defines the type, e.g. func(float foo, integer bar, string baz), and calling code with mixed up types won't even compile).

Yes, I've gone waaay beyond what was required to answer the question. Hopefully, someone down the line will find the extra info useful. :)

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.