mkdir() function to create those subdirectories and then set
directory to tell vim to use them. This snippet of code should work just fine:
call mkdir(a:path, "p", 0775)
" Find the nearest .git directory
let s:repo_root = ''
let s:cwd = getcwd()
while getcwd() != '/'
let s:repo_root = getcwd()
exec 'cd '.s:cwd
" If we found a .git/ directory somewhere, create directories there
if s:repo_root != ''
let s:dirpath = s:repo_root."/.vimfiles"
let &undodir = Mkdir(s:dirpath."/undo")
let &backupdir = Mkdir(s:dirpath."/backup")
let &directory = Mkdir(s:dirpath."/swp")
It's probably not a good idea to sync those files with git. Keep in mind that they will be constantly changing, and that will add a lot of clutter to your commits. Also there is no point in syncing
.swp files, since the whole point of having
.swp files is to avoid having two instances of the editor working on the same file at once. If you are syncing between different machines, these files stop making any sense.
I would suggest you don't put those files under your projects directory, but rather save them in subdirectories inside
~/.vim. In that case you only have to slightly modify the snippet above to remove the
.git/ discovery part, and to replace