title: How to expand variables in vim commands?
body: <p>I'm trying to get a variable expanded in a command call. Here's what I have in my <code>.vimrc</code>:</p>
  
  <pre><code>command! -nargs=1 -complete=dir TlAddPm call s:TlAddPm(&lt;f-args&gt;)
  function! s:TlAddPm(dir)
      let flist = system("find " . shellescape(a:dir) . " -type f -name '*.pm' | sort")
      TlistAddFiles `=flist`
  endfun
  </code></pre>
  
  <p>At the <code>:</code> prompt, the <code>&#96;=flist&#96;</code> syntax seems to work (or, at least it did with a <code>w:</code> variable), but in the <code>.vimrc</code> file it doesn't — TlistAddFiles is just passed the string <code>&#96;=flist&#96;</code>.</p>
  
  <hr>
  
  <p>Thanks to Andrew Barnett's and Mykola Golubyev's answers, I've now got this, which appears to work. Is there no better way?</p>
  
  <pre><code>command! -nargs=1 -complete=dir TlAddPm call s:TlAddPm(&lt;f-args&gt;)
  function! s:TlAddPm(dir)
      let findres = system("find " . shellescape(a:dir) . " -type f -name '*.pm' | sort")
      let flist = []
      for w in split(findres, '\n')
          let flist += [ fnameescape(w) ]
      endfor
      exe "TlistAddFiles " . join(flist)
  endfun
  </code></pre>