0

I'd like to use neovim to view man pages. To accomplish this, I have the following set in my .bashrc file:

export MANPAGER='nvim +Man!'

On my MacOS system this gives me no problems. But on my Linux system, opening a man page eventually comes up in neovim, but on startup for each man page brings up the following annoying message for about a second or two:

Error detected while processing function man#init_pager:
line   20:                                                                                                                                                                                                                                                                                    
E302: Could not rename swap file

I've found that this is related to putting my swap files in ~/.vim/swap because I prefer them there rather than polluting my working tree:

" Where to store swap files.  By default, they will go into ~/.vim/swap, but                                    
" if that doesn't work, they will go in cwd.                                    
set directory=~/.vim/swap,.                                     

I only see this with neovim, not vim.

Is there a way to get these two settings (using neovim as my MANPAGER and setting an alternate swap location) to work together?


In case it's helpful, this can be reproduced rather minimally like so:

docker pull ubuntu
docker run -it --name test_nvim_manpager ubuntu /bin/bash

apt update
apt install -y neovim man
unminimize

mkdir -p ~/.config/nvim
echo 'source ~/.vimrc' > ~/.config/nvim/init.vim

echo "export MANPAGER='nvim +Man\!'" >> ~/.bashrc
echo "set directory=~/.vim/swap,." >> ~/.vimrc
source ~/.bashrc

man ls

Update: This now happens with my mac running vim v0.7.2. I suspect that this now happens due to a vim upgrade, but I'm not sure now from what version.

1 Answer 1

0

In case it's helpful for someone else, I noticed that the filenames when vim is used as a MANPAGER starts with man://. With this in mind, I avoid switching the swap file location for man pages by wrapping the directive in a condition in my ~/.vimrc file:

" Changing the swap directory for the MANPAGER causes a "E302: Could not                                       
" rename swap file" error. Therefore do not change the swap directory for                                          
" man pages.   
if stridx(@%, 'man://') >= 0                                                                                      
  " Where to store swap files.  By default, they will go into ~/.vim/swap, but                                     
  " if that doesn't work, they will go in cwd.                                                             
  set directory=~/.vim/swap,.                                                                                      
endif                                                                                                      
                                                                                                                   

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .