title: How to configure Vim backup directories
body: <p>I dislike Vim cluttering my working directory with backup and swap files, but I don't want to turn them off in case something crashes. I found that adding lines like:</p>
  
  <pre><code>set backupdir=./.backup
  set directory=./.backup
  </code></pre>
  
  <p>in the Vim .vimrc configuration file tells Vim to put those files in a hidden directory. This is great except that if I do not manually create these hidden directories, it seems Vim does not create backup or swap files. I saw somewhere else lines like:</p>
  
  <pre><code>set backupdir=./.backup,/tmp,.
  set directory=./.backup,/tmp,.
  </code></pre>
  
  <p>and thought that this would tell Vim to use the other locations, <code>/tmp</code> or <code>.</code>, if it cannot use <code>./.backup</code>, but Vim does not seem to do so.</p>
  
  <p>How would I make Vim either: </p>
  
  <ol>
  <li>create the needed <code>./backup</code> directory, or </li>
  <li>use the working directory if the <code>./backup</code> directory does not exist?</li>
  </ol>