Executing :echo 'hello' prints "hello". Executing "=echo 'hello'<cr>p however, results in multiple errors.

Is there a way to execute Ex commands inside of the expression register?

  • 1
    What are you trying to do? From :help quote_=, "the expression must evaluate to a String". echo does not return a String, it prints a String.
    – gdupras
    Commented Aug 14, 2021 at 15:00
  • 2
    @gdupras not quite: the expression register expects an expression (:help expr), while :echo is a command.
    – D. Ben Knoble
    Commented Aug 14, 2021 at 16:08
  • @gdupras I was talking about executing an arbitrary command. :echo was just an example. Commented Aug 15, 2021 at 23:07

1 Answer 1


You use a command :echo in place of an expression :help expr.

There is however a function (whose invocation is an expr8 or expr9) that executes commands:

"=execute('echo "hello"')<CR>p

But in this case you probably just want


since 'hello' is an expression.

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.