title: How to use Windows environment variables in Vim script?
body: <p>I have a Vim script that calls an external shell script and reads the output into the current buffer. It works fine in Unix systems. I'm trying to make the script OS-agnostic, so I want it to work for Windows users too. Here's the relevant line from the script:</p>
  
  <pre><code>:exe ":0r !$HOME/bin/shell_script"
  </code></pre>
  
  <p>According to Vim's docs, <code>$HOME</code> should translate fine for Windows users too.  Using gvim on Win XP in command mode, doing</p>
  
  <pre><code>:echo $HOME
  </code></pre>
  
  <p>does indeed produce "C:\Documents and Settings\my_user".</p>
  
  <p>However, my Vim script (adjusted for backslashes) fails on the Windows machine with a message in the DOS cmd.exe window saying </p>
  
  <blockquote>
    <p>$HOME\bin\shell_script" not found.</p>
  </blockquote>
  
  <p>In other words, Vim appears not to be expanding the value of <code>$HOME</code> before passing it to cmd.exe.</p>
  
  <p>I can't use <code>%APPDATA%</code> either because Vim interprets <code>%</code> as the current file and pre/appends the file name to <code>APPDATA</code>.  Weird that Vim <em>does</em> expand <code>%</code> but doesn't expand <code>$HOME</code>.</p>
  
  <p>How do I get <code>$HOME</code> expanded correctly?  Is it because I'm using <code>exe</code> in the vim script?</p>