Adam Neal
Adam Neal

Reputation: 2177

Is there a way to pass arbitrary text to Vim?

I want a way to pass some literal text to Vim. I've seen that it can read from stdin with the "-" argument, so you can pipe things to it, e.g. the output of other commands.

But is there a way to pass any text into it like

vim - "Here's some random text"

and open Vim with that string in the buffer?

It complains if I try this command...

Upvotes: 8

Views: 875

Answers (3)

Eimantas
Eimantas

Reputation: 49344

$ echo "Here's some random text" | vim -

Upvotes: 21

Shizzmo
Shizzmo

Reputation: 16897

cat some_file | vim -

This is the correct way to pipe into vim.

Upvotes: 0

Mehrdad Afshari
Mehrdad Afshari

Reputation: 421978

echo string | vim -

Upvotes: 6

Related Questions