Vim可以让您使用外部程序的输出替换所选文本.我想利用我在Haskell中编写的程序来利用这一点.但它并没有将所选文本作为args.
- show-input.hs
module Main where
import System.Environment
main = do
input <- getArgs
putStr ("Input was: " ++ (show input))
Run Code Online (Sandbox Code Playgroud)
当我从命令行(NixOS GNU/Linux,BASH)运行它时,我得到了预期的行为:
$ ./show-input test
Input was: ["test"]
Run Code Online (Sandbox Code Playgroud)
当我在Vim中选择一些文本并调用时:'<,'>!~/show-input,我得到了这个:
Input was: []
Run Code Online (Sandbox Code Playgroud)
这里有一些奇怪的东西,但我不知道它是来自Vim传递参数的方式还是来自Haskell获取它们的方式.我尝试过使用控制台Vim和图形gVim(8.0.1451),结果相同.
NB:我可以成功使用Vim Bang!与其他外部程序,如grep.它很棒.
因此,对于任何感兴趣的人,只需替换getArgs为getContents,您就可以在字符串中输入所有内容(而不是字符串列表).
module Main where
import System.Environment
main = do
input <- getContents
putStr ("Input was: " ++ (show input))
Run Code Online (Sandbox Code Playgroud)
该!命令通过标准输入将选择的文本发送到程序,而不是命令行参数.等效的命令行将是somecommand | ./show-input.