0

I want to print stuff to the screen separated by key presses (any key). A reduced version of what I'm trying to do is:

$ echo banana && read -rsn1 && echo orange && read -rsn1 && echo apple

That works fine in bash, as expected.

However, I would like to do that inside vim (i.e., open vim, print banana, wait for key press, print orange, wait for key press, print apple), so I thought I could use process substitution for that:

$ vim <(echo banana && read -rsn1 && echo orange && read -rsn1 && echo apple)

Unfortunately, this doesn't work: only banana is printed. It looks like it can't capture key presses and blocks there. Why not? What is going on? How can I work around this?

0

1 Answer 1

2

I think the command you're looking for is

vim +"echo 'banana'" +"call getchar()" +"echo 'orange'" +"call getchar()" +"echo 'apple'"

The +"..." syntax allows to specify a vim command to execute after startup. Thus the line will use vim's echo to print the word in its command prompt followed by vim's getchar() which waits for a userinput (see :h getchar())

Now why your command didn't worked I may be wrong but I think that read expects an input on stdin which isn't what you modify when you press a key in vim.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.