1

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?

3
  • 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
    Aug 14 at 15:00
  • 2
    @gdupras not quite: the expression register expects an expression (:help expr), while :echo is a command.
    – D. Ben Knoble
    Aug 14 at 16:08
  • @gdupras I was talking about executing an arbitrary command. :echo was just an example. Aug 15 at 23:07
4

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

"='hello'<CR>p

since 'hello' is an expression.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.