2

I'm trying to put the output of a command into a QuickFix list when a particular key is pressed. That command takes as its argument the word under the cursor, so my function looks basically like this (example; ls is not actually my command):

set makeprg=ls\ $*

function MyFunction()
    let word = expand("<cword>")
    silent make word
    copen
endfunction

And what it does is call with the literal word word. If I use a $ before it, then the literal $ is used also.

How do I put the value of word into make instead of those four letters?

1 Answer 1

3

Most ex commands (except for :echo and :exe) take their arguments literally and do not evaluate VimScript expressions. To make that work, you need to wrap your command into an :exe command.

So you would need to do:

:exe "sil make" word

Have also a look the help :h :exe

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.