how do I use a variable content as an argument for vim command?

what about:

:execute ':grep ' . foo

It's not about variable but maybe vim abbreviate command can helps. Try from command line:

:abbreviate foo pattern

Then

:Ggrep foo<space>

It will complete 'foo' to your 'pattern'.


If you don't like the :exe solution, you can "read" the contents of a variable into to the command line by using the = expression register. For example, type :Ggrep then press Ctrl-r and then type =foo and press Enter. Assuming the variable foo contained "pattern", your command line should now look like:

:Ggrep pattern

This has the advantage that you can see the actual command that will be run, and even modify it before pressing Enter a second time.

See:

:help "=

Tags:

Vim