Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

for example suppose I did

:let foo=pattern

and now I want to perform Ggrep patter but use variable foo instead of the literal patter string.

:echo foo

outputs pattern, but

:Ggrep foo

just looks for foo

UPDATE:

building a string of command and then running :execute on it is not a solution, its a hack. And it breaks with any non-trivial variable values.

share|improve this question
    
what is Ggrep (capital G?)? –  akira Aug 8 '11 at 11:30
    
git grep from 'fugutive' vim plugin –  Vitaly Kushner Aug 9 '11 at 10:08

1 Answer 1

what about:

:execute ':grep ' . foo
share|improve this answer
    
how do I properly escape foo's content? it might contain special characters like ", ', /, \, etc –  Vitaly Kushner Aug 8 '11 at 11:34
1  
@Vitaly Kushner: See ":help escape()" and ":help fnameescape()". –  garyjohn Aug 8 '11 at 16:45
    
I know escape(), but not sure about what characters to escape –  Vitaly Kushner Aug 10 '11 at 13:00
    
fnameescape() is not good, its not a filename argument, its an arg to plugin function. suppose I :let foo = "aaa\"bbbb'cccc" –  Vitaly Kushner Aug 10 '11 at 13:02
    
i think that 'how to escape a regular expression bullet-proof in vim' is another question, either here or on stackoverflow.com. –  akira Aug 10 '11 at 17:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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