0

I'm trying to disable autochdir in nvim by adding the following in init.vim:

set autochdir!

but when I start nvim, I check the value of this option by echo &autochdir and find it equals to 1.

I though it may be overwritten by Python filetype as mentioned these two posts (Why is “set noexpandtab” in my ~/.vimrc ignored when I open a file? and Vim displaying incorrect indentation).So I tried adding the following to my vimrc:

augroup python
    autocmd!
    autocmd FileType python set autochdir!
augroup end

but it doesn't solve the problem.

Why is this option overwritten and how can I force it?

Salahuddin Ahmed
  • 441
  • 3
  • 14

1 Answers1

1

Something funny is going on here. If you want to disable the 'autochdir', use

:set noautochdir

If you use the the !, this means it basically toggles the option. So whenever you happen to resource your .vimrc (or init.vim) file it silently toggles the value, which might be unexpected.

However, if you read the help for that setting, it clearly indicates this option is off by default. So you can also just skip the whole command at all ;)

augroup python
    autocmd!
    autocmd FileType python set autochdir!
augroup end

Secondly your autocommand may work fine and disable the autochdir. Sadly, this might come to late so that Nvim already switched to the specified directory and only afterwards it turns off the setting.

You can always check the option value when it was set and by what script by using:

:verbose set autochdir?

In general I would always recommend to either leave this global option off, or on. But do not toggle it often within a session. It might be confusing, but your mileage may vary.

Christian Brabandt
  • 25,820
  • 1
  • 52
  • 77