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

Editorconfig settings lost on file reload

Open lu-zero opened this issue 5 years ago • 7 comments

I noticed that upon reloading a file the editorconfig overrides are lost.

To reproduce:

  • open a file in a project with an editorconfig setup (in my case rav1e)
  • start editing a file and save the changes
  • git checkout -f from another terminal
  • let vim reload the file once it notices
  • notice that the editorconfig settings are lost

Also:

  • open a file with a spurious state (e.g. another vim was editing it and got killed)
  • answer to the prompt
  • notice that the editorconfig settings are not present

lu-zero avatar May 02 '19 09:05 lu-zero

let vim reload the file once it notices

Did you manually do this or some plugin did it automatically for you?

xuhdev avatar May 02 '19 20:05 xuhdev

it is the normal behavior on mac

lu-zero avatar May 02 '19 20:05 lu-zero

  • By "the editorconfig overrides are lost", do you mean the tabstop, shiftwidth, &c. are no longer set to what you expect based on your .editorconfig file?
  • What OS and Vim versions?

Thanks!

cxw42 avatar Jun 09 '20 12:06 cxw42

macOS, 8.2

lu-zero avatar Jun 09 '20 13:06 lu-zero

I'm also seeing this behaviour on Ubuntu.

Ubuntu: 20.04 Vim: vim-gtk3 2:8.1.2269-1ubuntu5.7

I have the following in ~/.vim/ftplugin/javascript.vim

setlocal shiftwidth=4
setlocal tabstop=4

In the root dir of my project, I have the following .editorconfig:

root = true

[*.js]
indent_style=space
indent_size=2

Reproduction steps:

  • Edit a .js file and save it (indent settings picked up from .editorconfig correctly at this point)
  • Switch to a terminal and make another change (eg with git checkout -f)
  • Switch back to the vim window, and see the "File has changed" prompt, and load the file:

    W11: Warning: File "path/to/file.js" has changed since editing started See ":help W11" for more info. [O]K, (L)oad File:

  • Observe that the indent settings are now the ones from the .vimrc, not the .editorconfig
    :set sw? ts?
    shiftwidth=4
    tabstop=4
    
  • Reload the file with :e, and the settings from .editorconfig are picked up correctly again.

alext avatar Mar 18 '22 09:03 alext

@alext thanks! I can repro following your steps above.

I agree that .editorconfig should override the ftplugins on reload, as it does on :e.

cxw42 avatar Mar 20 '22 21:03 cxw42

It looks like this might be an issue in vim itself. In the reload case, FileType is invoked twice, once after BufRead. Since we hook BufRead, the FileType work (including ftplugins) overrides what we did in BufRead. Logfile diff: image

To re-create: set up the files as above, and do

$ rm log.txt ; gvim '-nN' '-i' 'NONE' -V100log.txt test.js

then pull out the relevant sections of the log for reload and :e, and do

:g/Executing.*Autocommands\|s:UseConfig\|ftplugin.javascript.vim/p

to get the relevant events.

Any Vim-internals folks who might be willing to file the issue upstream? If not, I can do my best, but I haven't touched vim's internals at all.

cxw42 avatar Mar 20 '22 21:03 cxw42