What is the correct way to make git ignore temporary files produced by vim in all directories (either globally across the system or locally for a single project)?
Alternatively you can configure vim to save the swapfiles to a separate location, e.g. by adding lines similar to the following to your .vimrc file:
.vimrc
set backupdir=$TEMP// set directory=$TEMP//
See this vim tip for more info.