Why is Neovim's init file not working on my Mac?

Viewed 4849

(Using MacOS) For some reason, the ~/.config/nvim file was not provided by default. So I created that directory and in it, the init.vim file.

The init.vim file has the following:

set runtimepath^=~/.vim runtimepath+=~/.vim/after
let &packpath=&runtimepath
source ~/.vimrc

This is supposed to get Neovim to use the settings I wrote in .vimrc

For some reason, the settings I have wrote in .vimrc are not showing up when I use neovim. What's going on?

2 Answers

Is the $XDG_CONFIG_HOME environment variable defined in your shell? If so, Neovim will look for an init.vim (or init.lua) in $XDG_CONFIG_HOME/nvim instead of ~/.config/nvim.

Here is the pertinent help text from :h init.vim:

    The Nvim config file is "init.vim", located at:
        Unix        ~/.config/nvim/init.vim
        Windows     ~/AppData/Local/nvim/init.vim
    or if |$XDG_CONFIG_HOME| is defined:
                $XDG_CONFIG_HOME/nvim/init.vim

On my Mac, it was because of the access permission with the ~/.config folder. There was a red minus sign on the folder when viewed in Finder. I tried to open it and got this message:

The folder “.config” can’t be opened because you don’t have permission to see its contents.

I figured this was the problem because when I ran Neovim with sudo nvim, all the customisations in the init.vim file were applied.

I removed the restriction on the ~/.config folder by running this in the command line (source):

sudo chown [user] ~[user]/.config

and then

chmod 711 ~[user]/.config

Change [user] with the name of your home directory.

Related