I want to use ! with powershell. I use neovim natively on windows.

I tried these settings

set shell=powershell.exe
set shellcmdflag=-NoProfile\ -NoLogo\ -NonInteractive\ -Command
set shellpipe=|
set shellredir=>

as suggested here https://robindouglas.uk/powershell/vim/2018/04/05/PowerShell-with-Vim.html

They don't work (having nvim -u NONE from cmd or neovim-qt). They simply return the same command I typed.

I tried using this and additionally, set set shellquote=\" I get on !ls:

+ ""ls""
+   ~~~~
Unexpected token 'ls""' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken


2 Answers 2


OK, I didn't notice it . There is actually in help shell-powershell

The settings are

        let &shell = has('win32') ? 'powershell' : 'pwsh'
        let &shellcmdflag = '-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command [Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.Encoding]::UTF8;'
        let &shellredir = '2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode'
        let &shellpipe = '2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode'
        set shellquote= shellxquote=
  • 1
    What the hell :( It's too hard to decipher :( Feb 20 at 14:17
  • Is the last = a typo? Feb 20 at 14:21
  • No, it actually work
    – eyal karni
    Feb 24 at 4:27
  • So you put this in an init.vim beside your init.lua? Feb 24 at 13:02
  • I use .vimrc. Zz
    – eyal karni
    Mar 3 at 7:33

to add up to the above solution and since OP specifically asked about Neovim, you're most likely using an init.lua, so here's the Lua equivalent.

I'd personally get rid of the if statement altogether and just use 'pwsh',
since this makes it use Windows Powershell instead of Powershell Core
in the case you are using the latter. Since it's an equivalent I'll leave it
if vim.fn.has('win32') == 1 then
  vim.o.shell = 'powershell'
  vim.o.shell = 'pwsh'

vim.o.shellcmdflag = '-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command [Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.Encoding]::UTF8;'
vim.o.shellredir = '2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode'
vim.o.shellpipe = '2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode'
vim.o.shellquote = ''
vim.o.shellxquote = ''

Albeit personally, I prefer the :term command with a mapping instead to open a terminal in a split window, it's available in Vim 8.0+

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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