为什么我的Haskell cmd line程序不能从Vim Bang获得参数?

时间:2018-11-08 14:50:59

标签: haskell vim

Vim可以让您用外部程序的输出替换选定的文本。我想利用我在Haskell中编写的程序来利用这一点。但是它不会将所选文本作为args。

-show-input.hs

module Main where

import System.Environment

main = do
    input <- getArgs
    putStr ("Input was: " ++ (show input))

当我从命令行(NixOS GNU / Linux,BASH)运行它时,我得到了预期的行为:

$ ./show-input test
Input was: ["test"]

当我在Vim中选择一些文本并调用:'<,'>!~/show-input时,我得到以下信息:

Input was: []

这里有些奇怪,但是我无法确定这是因为Vim传递参数还是Haskell传递参数。我已经尝试使用控制台Vim和图形gVim(8.0.1451),但结果相同。


注意:我可以成功使用Vim Bang!与其他外部程序,例如grep。效果很好。

---

chepner回答后的正确版本

因此,对于感兴趣的任何人,只需将getArgs替换为getContents,您就可以将输入全部输入字符串(而不是字符串列表)中。

module Main where

import System.Environment

main = do
    input <- getContents
    putStr ("Input was: " ++ (show input))

1 个答案:

答案 0 :(得分:6)

!命令通过标准输入而不是命令行参数将选定的文本发送到程序。等效的命令行为somecommand | ./show-input

相关问题