· nvim til

nvim: Unable to create directory for swap file - recovery impossible: permission denied

I was playing around with neovim last week and despite installing it via Homebrew, ran into a weird permissions error. In this blog post, I’ll describe the problem I had and how to solve it.

I installed it like this:

brew install nvim

And then tried to create a new file:

nvim foo.py

Which resulted in the following error:

Output
E303: Unable to create directory "/Users/markhneedham/.local/state/nvim" for swap file, recovery impossible: permission denied
E303: Unable to open swap file for "foo.py", recovery impossible

Hmm, let’s take a look at what’s in my ~/.local directory.

ls -alh ~/.local
Output
total 0
drwxr-xr-x    6 markhneedham  staff   192B 29 Nov 21:40 .
drwxr-x---+ 149 markhneedham  staff   4.7K  2 Jan 23:37 ..
drwxr-xr-x@   5 markhneedham  staff   160B 19 Dec 06:22 bin
drwxr-xr-x@   6 markhneedham  staff   192B 29 Nov 21:40 pipx
drwxr-xr-x    5 markhneedham  staff   160B  2 Jan 23:31 share
drwxr-xr-x    3 root          staff    96B 14 Feb  2023 state

Weird, it’s made root the owner of the state directory, whereas I need it to be markhneedham. But we can fix that using chown:

sudo chown  ~/.local/state markhneedham:staff

And now if we open a file with nvim it’s happy!

  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket