0

I'm new to neovim (and vim in general), and I'm trying to use it on Windows with MSYS2. I noticed they have a package for vim, but not for neovim. I used the neovim installed through chocolatey instead, but I couldn't get the :!{cmd} command to work. It returns "/usr/bin/bash: /s: No such file or directory". Neovim seems to work normally otherwise, including the :terminal command. Is there a way to get around this problem without changing the shell to cmd/powershell?

4
  • Start with :h 'shell'. Set that to the location of MSYS2's bash.exe
    – B Layer
    Aug 29 at 18:44
  • This didn't seem to work. I believe the shell was already correctly set, as running :set shell would print out the correct path to bash.exe, and setting it in init.vim did not make any difference. Aug 29 at 19:29
  • Maybe check shellcmdflag? Not sure why it would include /s though. I can't find anything relevant in the help matching \/s\>
    – D. Ben Knoble
    Aug 29 at 20:50
  • The last paragraph of this answer vi.stackexchange.com/a/31136/11054 describes a method for debugging how Vim is invoking the shell. It might shine a light on what is happening including what that /s is.
    – B Layer
    Aug 29 at 22:40
1

The comments by B layer and Ben Knoble were both helpful in finding the answer.

Vim correctly set the shell based on the $SHELL variable, but did not set shellcmdflag appropriately, and that was what the /s was, the default shellcmdflag for cmd.exe, as stated in the :help 'shell' file.

Setting it to -c in my init.vim seems to have solved the problem, and a similar solution found in https://www.gitmemory.com/issue/mattn/vim-lsp-settings/234/631950449 seems to indicate that it might be useful to also set the shellxquote and shellslash variables. Unlike him, I did not set my PATH or the shell variable itself as I ran neovim from within MSYS2.

I added the following to vim.init so I could still use cmd.exe if I were to run nvim externally.

if $SHELL == "C:/msys64/usr/bin/bash"
    let &shellcmdflag = '-c'
    set shellxquote=(
    set shellslash
endif

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.