You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过init.lua在NeoVim中设置PowerShell为默认终端?

在NeoVim中通过init.lua设置PowerShell为默认终端

直接在你的init.lua配置文件中添加以下代码,即可将PowerShell设为NeoVim的默认终端:

-- 配置默认终端为PowerShell
vim.opt.shell = "pwsh.exe"
vim.opt.shellcmdflag = "-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command [Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.Encoding]::UTF8;"
vim.opt.shellredir = "2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode"
vim.opt.shellpipe = "2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode"
vim.opt.shellquote = ""
vim.opt.shellxquote = ""

配置说明

  • vim.opt.shell:指定使用的Shell程序。若你用的是Windows自带的传统PowerShell(而非PowerShell Core),将值改为powershell.exe即可;如果PowerShell不在系统PATH中,需填写完整路径,比如"C:\\Program Files\\PowerShell\\7\\pwsh.exe"(注意Lua中反斜杠需要转义)。
  • shellcmdflag:设置PowerShell的启动参数,-NoLogo去掉启动logo,-NoProfile不加载用户配置文件避免干扰,-ExecutionPolicy RemoteSigned确保脚本可正常执行,最后设置UTF8编码解决乱码问题。
  • shellredir/shellpipe:处理终端输出的重定向和管道编码,保证输出内容不会出现乱码。
  • shellquote/shellxquote:清空引号配置,避免PowerShell解析命令参数时出现冲突。

内容的提问来源于stack exchange,提问作者MitchW

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 08:17:09