Settings not applied for files in new directory
If you edit a file which does not exist, editorconfig settings are applied, but if you edit a file in a directory which does not exist, editorconfig settings are not applied.
~/.editorconfig:
[*.js]
indent_style = space
indent_size = 2
vim foo.js, :verb set et? sw?:
expandtab
Last set from ~/.vim/plugged/editorconfig-vim/plugin/editorconfig.vim line 547
shiftwidth=2
Last set from ~/.vim/plugged/editorconfig-vim/plugin/editorconfig.vim line 563
vim foo/bar.js, :verb set et? sw?:
noexpandtab
shiftwidth=8
I can reproduce this on Vim 8.0 + 1-1453 on Ubuntu. Thanks for reporting!
For context, what is your use case? I agree this is a surprising behaviour, but there's not much you can do with a file in a nonexistent directory :) .
I have the following snippet in my vimrc, which automatically creates any missing directories on save (credit to Stack Overflow):
fun! s:CreateNonexistentDirs(file, buf) abort
if empty(getbufvar(a:buf, '&buftype')) && a:file!~#'\v^\w+\:\/'
let dir=fnamemodify(a:file, ':h')
if !isdirectory(dir)
call mkdir(dir, 'p')
endif
endif
endfun
augroup BWCCreateDir
au!
au BufWritePre * :call s:CreateNonexistentDirs(expand('<afile>'), +expand('<abuf>'))
augroup end
Nice!
Per editorconfig/editorconfig-vote#8, nonexistent directories should now be treated as if existing and empty. Therefore, this is officially a bug in the editorconfig-vim plugin, and I have labeled it as such. Thanks for reporting! It's on the list.