1

I'm trying to insert a filename into text as below:

:put=expand("%")

but I've the following errors:

E116: Invalid arguments for function expand(
E15: Invalid expression: expand(

Why this doesn't work?

What's most surprising thing is that it works when using single-quote instead, e.g.:

:put=expand('%')

So I'm trying to understand:

  • Is there any differences between using double-quotes or single-quotes? If so, what kind?

I'm using Vim v7.4.

6
  • For assign to variable you should use let keyword. let put=expand("%")
    – Alex Kroll
    Oct 19, 2015 at 11:02
  • 1
    @AlexKroll, :help :put.
    – romainl
    Oct 19, 2015 at 11:08
  • @romainl Yeh. If you exactly wont to put text into your buffer you should use function like :call append(line('.'), expand("%")) it put result of expand() line bellow cursor.
    – Alex Kroll
    Oct 19, 2015 at 11:11
  • :put puts text from register like this :let @x=expand("%") | put x
    – Alex Kroll
    Oct 19, 2015 at 11:16
  • 3
    @AlexKroll, so does put=expand('%').
    – romainl
    Oct 19, 2015 at 11:16

1 Answer 1

5
  • From :help :put:

    The register can also be = followed by an optional expression. The expression continues until the end of the command. You need to escape the | and " characters to prevent them from terminating the command.

  • For the difference between " and ' in the context of an expression, see :help expr-quote and :help expr-'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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