0

I apologize in advanced for what appears to be such a simple question.

I have a sample command defined as follows:

command! -nargs=+ Exmpl call Example(<f-args>)
function! Example(name)
    echo a:name
endfunc

It is invoked as follows:

Exmpl 'hello'

but it seems to literally interpret arguments given without parsing. So:

let hello = 'world'
Exmpl hello

Does not print world, as expected.

This is clearly something obvious I can't find in the literature. I've tried adding a variety of escape characters like &, but the subsequent arguments are always treated as bare words.

How can I use variables in custom Vim commands?

1
  • You can use :debug to see what's really executed -> :debug Exmpl hello + s + ENTER + s + ENTER ... Commented Jun 14, 2017 at 8:17

1 Answer 1

2

Using <args> instead of <f-args> does what you are asking.

This command definition expands any supplied arguments when invoked

command! -nargs=+ Example call Example(<args>)
function! Example(name)
      echo a:name
endfunc

let hello = 'world'
Exmpl hello

Output

world

Reference

:help command

then search the help text for: /tab<args>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.