martz
martz

Reputation: 849

How to expand function arguments in Vim command line?

Vim's Utl plugin offers a convenient way for doing web queries from within the editor. When called directly from the command line, a dictionary lookup can be done like this:

:Utl ol http://dict.leo.org/?search=my+search+term

What's the correct way for defining a custom command with the same purpose (my+search+term being user input)? I can't seem to get <f-args> right with this one:

command -nargs=1 SearchLeo :exe ":Utl ol http://dict.leo.org/?search=" . expand("<f-args>")

What's the correct way of defining function arguments here? Or should I turn this into a more complete function? Thanks!

Upvotes: 3

Views: 1926

Answers (1)

Ingo Karkat
Ingo Karkat

Reputation: 172540

  1. You probably don't need expand() here; it's just for expanding globs (like *.txt) or the special variables like % for the current file.
  2. You're quoting the argument twice, once through <f-args> (<q-args> would be slightly more correct, though it only matters with a variable number of arguments), once literally.

Use this:

command -nargs=1 SearchLeo :exe ":Utl ol http://dict.leo.org/?search=" . <q-args>

Upvotes: 4

Related Questions