I see from :h printf that there's a print function in vim:

printf({fmt}, {expr1} ...) printf() Return a String with {fmt}, where "%" items are replaced by the formatted form of their respective arguments. Example: printf("%4d: E%d %.30s", lnum, errno, msg)

However, when I try doing something basic like:

:printf('Hello, %s', 'name')

I get the following error:

E492: Not an editor command: printf('Hello, %s', 'name')

What would be the correct usage, if any, of the printf command, and where can it be used?

1 Answer 1


printf() is a function, not a command. And in Vim everything must start with a command.

So while calling a function either put it on rhs, or use :call command (when you don't care for return value).

But note that printf() is analog to sprintf() in C, so :call printf(...) doesn't make any sense. So you must do

:echo printf('Hello, %s', 'name')

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.