如何使用powershell过滤来自vim的行

时间:2013-12-21 13:29:00

标签: powershell vim

我有以下文件:

firstname,lastname,email
jane,doe,jane@example.com
drew,neil,drew@vimcasts.org
john,smith,john@example.com

我执行1,$!sort -property @{"Expression"={$_.split(',')[1]}}

它输出以下错误:

At line:1 char:49
+ sort -property @{Expression={$_.split(',')[1]}} <C:/Users/wild/AppData/Local/Tem ...
+                                                 ~
The '<' operator is reserved for future use.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : RedirectionNotSupported

在我的_vmrc

set shell=powershell\ -ExecutionPolicy\ Unrestricted\ -NoProfile\ -NoLogo\ -NonInteractive
set shellcmdflag=-command
set shellpipe=|
set shellredir=>

此外,我尝试过没有here的结果:

if has("win32")
     set shell=cmd.exe
     if has("gui_running")
     set shellcmdflag=/c\ chcp\ 65001\ &&\ powershell.exe\ -NoLogo\ -NoProfile\ -NonInteractive\ -ExecutionPolicy\ RemoteSigned
     else
     set shellcmdflag=/c\ powershell.exe\ -NoLogo\ -NoProfile\ -NonInteractive\ -ExecutionPolicy\ RemoteSigned
     endif
     set shellpipe=|
     set shellredir=>
endif

如何将Sort-Object cmdlet与vim一起使用?

2 个答案:

答案 0 :(得分:2)

我遇到了同样的问题。从理论上讲,您应该能够使用管道而不是输入重定向运算符'&lt;'通过在Vim中设置 noshelltemp ,但它目前尚未在Windows中实现:

  

'shelltemp''stmp'boolean(Vi默认关闭,Vim默认开启)

     

全球

     

{Vi not Vi}

     

启用时,使用shell命令的临时文件。什么时候关   用管子。使用管道时,无法使用临时文件   无论如何。目前只在Unix上支持管道。

所以,看起来我们现在被困住了......

答案 1 :(得分:0)

纯粹从PS用户的角度来看:这种方法的问题在于,PowerShell(作为错误消息试图解释)没有<运算符。这是少数保留但尚未实施的(可能是由于需求相对较低)。

除非有办法强制vim使用带有管道元素的“常用”PowerShell语法到Sort-Object,否则你不会走得太远。