This is a card in Dave's Virtual Box of Cards.

Vim's call command

Created: 2022-03-01

When writing Vim scripts and/or working with ex commands (at the : prompt), it’s important to know the difference between functions and commands.

Anything you can run directly at the : prompt is a command:

:echo "Foo!"

Vim also supplies functions (and you can write your own). To run a function and throw away the return value, use the call command:

:function Hello(myarg)
:   echo "Hello " . a:myarg

:call Hello("world")

But you aren’t limited to call - any command that takes an expression can receive the output of a function, such as echo or echom (saves to message history):

:echo Hello("world")