带有 Powershell 的 Vim [英] Vim with Powershell
问题描述
我在 Windows 上使用 gvim.
在我的 _vimrc 中,我添加了:
set shell=powershell.exe设置 shellcmdflag=-c设置 shellpipe=>设置 shellredir=>功能!测试()回声系统(目录-名称")端功能命令!-nargs=0 测试:调用测试()
如果我执行这个函数 (:Test),我会看到无意义的字符(非数字/字母 ASCII 字符).
如果我使用 cmd 作为 shell,它可以工作(没有 -name),所以问题似乎是从 powershell 输出到 vim.
有趣的是,这很好用:
:!dir -name
就像这样:
:r !dir -name
更新:确认 David
如果在 _vimrc 中执行上面提到的 set 命令,:Test 输出无意义.但是,如果您直接在 vim 中而不是在 _vimrc 中执行它们,则 :Test 会按预期工作.
另外,我试过使用 iconv 以防它是编码问题:
:echo iconv( system("dir -name"), "unicode", &enc )
但这没有任何区别.不过我可能使用了错误的编码类型.
有人知道怎么做吗?
这有点麻烦,但以下内容在 Vim 7.2 中有效.请注意,我在 CMD 会话中运行 Powershell.
if has("win32")设置外壳=cmd.exeset shellcmdflag=/c\ powershell.exe\ -NoLogo\ -NoProfile\ -NonInteractive\ -ExecutionPolicy\ RemoteSigned设置 shellpipe=|设置 shellredir=>万一功能!测试()回声系统(目录名称")端功能
经过以下测试...
:!dir -name
:调用Test()
I'm using gvim on Windows.
In my _vimrc I've added:
set shell=powershell.exe
set shellcmdflag=-c
set shellpipe=>
set shellredir=>
function! Test()
echo system("dir -name")
endfunction
command! -nargs=0 Test :call Test()
If I execute this function (:Test) I see nonsense characters (non number/letter ASCII characters).
If I use cmd as the shell, it works (without the -name), so the problem seems to be with getting output from powershell into vim.
Interestingly, this works great:
:!dir -name
As does this:
:r !dir -name
UPDATE: confirming behavior mentioned by David
If you execute the set commands mentioned above in the _vimrc, :Test outputs nonsense. However, if you execute them directly in vim instead of in the _vimrc, :Test works as expected.
Also, I've tried using iconv in case it was an encoding problem:
:echo iconv( system("dir -name"), "unicode", &enc )
But this didn't make any difference. I could be using the wrong encoding types though.
Anyone know how to make this work?
It is a bit of a hack, but the following works in Vim 7.2. Notice, I am running Powershell within a CMD session.
if has("win32")
set shell=cmd.exe
set shellcmdflag=/c\ powershell.exe\ -NoLogo\ -NoProfile\ -NonInteractive\ -ExecutionPolicy\ RemoteSigned
set shellpipe=|
set shellredir=>
endif
function! Test()
echo system("dir -name")
endfunction
Tested with the following...
:!dir -name
:call Test()
这篇关于带有 Powershell 的 Vim的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!