Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a folder, if it doesn't exist, from .vimrc?

Tags:

vim

I don't like how vim clutters up my folders with backup files, so I have the following line in my .vimrc file:

set backupdir=~/.vim_backup 

However, sometimes this folder doesn't exist because of new machines where I am copying my user files over.

How can I create this folder automatically, if it doesn't exist, from within .vimrc? Or is there some better way to deal with this situation?

like image 718
Fragsworth Avatar asked Oct 10 '09 22:10

Fragsworth


People also ask

Why does mkdir not create directory?

mkdir: cannot create directory – Permission denied The reason for this error is that the user you're running the mkdir as, doesn't have permissions to create new directory in the location you specified. You should use ls command on the higher level directory to confirm permissions.


1 Answers

I think this is operating system independent:

if !isdirectory("/my/directory")     call mkdir("/my/directory", "p") endif 
like image 90
jdg Avatar answered Sep 28 '22 05:09

jdg