editorconfig-vim icon indicating copy to clipboard operation
editorconfig-vim copied to clipboard

Settings not applied for files in new directory

Open sersorrel opened this issue 5 years ago • 4 comments

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

sersorrel avatar Jul 29 '19 19:07 sersorrel

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 :) .

cxw42 avatar Jul 30 '19 12:07 cxw42

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

sersorrel avatar Jul 30 '19 21:07 sersorrel

Nice!

cxw42 avatar Jul 31 '19 02:07 cxw42

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.

cxw42 avatar Aug 18 '19 00:08 cxw42