How to open VIM from a crystal program?

I couldn’t find it on https://crystal-lang.org/api/, https://crystal-lang.org/reference, or https://github.com/askn/crystal-by-example but someone on Gitter mentioned

Process.run(ENV\["EDITOR"\], args: {"myfile.txt"})

When I run crystal src/note.cr the program just terminated after about a second and I don’t see VIM.

I posted it also on reddit so instead of commenting both here and there i’ll just link to the reddit discussion:

Process.run does not connect stdout, stderr and stdin by default, you need to do it explicitly:


Process.run("vim", output: :inherit, error: :inherit,  input: :inherit)

EDIT: Or actually just use system: system("vim").

1 Like