Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Behavior of init.vim autocommands has changed, due to neovim's enabling syntax and filetypes by default #4684

Closed
bradst opened this issue Apr 30, 2016 · 2 comments
Labels
bug issues reporting wrong behavior has:repro issue contains minimal reproducing steps ux user experience

Comments

@bradst
Copy link

bradst commented Apr 30, 2016

  • Neovim version: 0.1.4 git HEAD
  • [?] Vim behaves differently? Vim version:
    • vim does not run filetype plugin indent on and syntax on by default
  • Operating system/version: Arch Linux
  • Terminal name/version: any
  • $TERM: any

Actual behaviour

Since recently, neovim enables filetypes and syntax by default. Following HEAD states that users can simply delete those lines from their configuration. However, if the user removes filetype plugin indent on from their configuration, autocmd FileType lines in init.vim may no longer override settings applied by a filetype plugin. For example, autocmd FileType * setlocal formatoptions-=ro does not override formatoptions applied by a filetype plugin unless filetype plugin indent on has already been run before the autocommand is defined. The new syntax/filetype default is applied by neovim after init.vim, so if filetype plugin indent on is removed from init.vim, affected autocommands will not work as expected.

Expected behaviour

User configurations should continue to work as expected, or documentation should be updated to inform users how to update their init.vim.

Steps to reproduce using nvim -u NORC

This issue depends on a minimal init.vim, so here are two:

This is an example of a working config before neovim supported enabling syntax/filetypes by default:

" before.vim
filetype plugin indent on
autocmd FileType * setlocal formatoptions-=ro

This next config is an example of a user following the documentation and removing the filetype line, which is assumed to be redundant with the new default:

" after.vim
autocmd FileType * setlocal formatoptions-=ro

We also need a file that will trigger an ftplugin which sets formatoptions:

$ echo '# comment' > test.conf

Now we are ready:

nvim -u before.vim test.conf
:set fo?

You should see formatoptions=jcql. This is the expected behavior; ro options have been removed by the autocommand.

nvim -u after.vim test.conf
:set fo?

You should see formatoptions=jcroql. The ro options have not been removed by the autocommand.

@justinmk justinmk added has:repro issue contains minimal reproducing steps ux user experience bug issues reporting wrong behavior labels Jan 17, 2017
@justinmk
Copy link
Member

justinmk commented Jan 17, 2017

Confirmed. The old behavior accidentally works because users "probably" call :filetype plugin indent on before setting up autocmds. So the user's autocmds run after the :filetype autocmds.

Workaround 1:

A workaround is to setup the FileType handler on VimEnter:

au VimEnter * au FileType * setlocal formatoptions-=ro

However that workaround doesn't work for files loaded from the command line (nvim file1 file2 ...), because VimEnter happens after those files are loaded. :edit on the buffer fixes it.

Workaround 2:

Things should work just fine if you put filetype plugin indent on in your init.vim as you would in Vim. Nvim's auto-enable logic will be skipped in that case.

@justinmk
Copy link
Member

justinmk commented Oct 8, 2017

Merging this with #7367

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug issues reporting wrong behavior has:repro issue contains minimal reproducing steps ux user experience
Projects
None yet
Development

No branches or pull requests

2 participants