Avatar

Hund[en]

Linux, plaintext & minimalism
June 26, 2020

How to automatically change the current working directory in Neovim

Something that has been overly annoying ever since I switched over to Neovim from Vim is the fact that my working directory has alway been my home folder, no matter what file I’m editing.

I first though it was an issue with the plugin Ranger.vim and I didn’t do anything about it. I exclusively use that plugin to navigate my filesystem and open files in Neovim using Ranger (and previously in Vim) and I can’t live without it.

It wasn’t until I recently that I noticed that I had the same issue when using the built in command :edit that I did some research about it and found out about the feature autochdir:

'autochdir' 'acd'       boolean (default off)
                        global
        When on, Vim will change the current working directory whenever you
        open a file, switch buffers, delete a buffer or open/close a window.
        It will change to the directory containing the file which was opened
        or selected.

When enabled it means that when I’m working on a file in the folder $HOME/example/ and then open a new buffer and spawn Ranger inside Neovim (or just using :edit) I end up in the folder $HOME/example and no in my home folder $HOME/.

Source: https://vim.fandom.com/wiki/Set_working_directory_to_the_current_file.

Tags: Neovim | Vim

Feedback

I don't have a commenting system simply because I haven't found a solution that I like. If you want to leave any feedback and/or have any questions feel free to contact me either via e-mail, the fediverse, by XMPP or by IRC (I'm Hund at freenode.net).