Why doesn't my Haskell cmd line program get arguments from Vim Bang?

1040 views haskell
1

Vim has the possibility to let you replace selected text with the output of an external program. I'd like to take advantage of this with programs that I'd write in Haskell. But it doesn’t get the selected text as args.

-- show-input.hs

module Main where

import System.Environment

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

When I run it from the command line (NixOS GNU/Linux, BASH), I get the expected behavior:

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

When I select some text in Vim and invoke :'<,'>!~/show-input, I get this :

Input was: []

There is something weird here, but I can't tell if it is from the way Vim passes arguments or from the way Haskell gets them. I have tried with both console Vim and graphical gVim (8.0.1451), with the same result.


NB: I can successfully use Vim Bang! with other external programs, such as grep. It works great.

answered question

1 Answer

4

The ! command sends the seleted text to the program via standard input, not as a command line argument. The command line equivalent would be somecommand | ./show-input.

posted this

Have an answer?

JD

Please login first before posting an answer.