7

I would like to view the output of echo in vim, and save to a file after having a look at it. I have tried echo $PATH | vim, but I get the following error:

Vim: Warning: Input is not from a terminal
Vim: Error reading input, exiting...

Vim: Finished.

What can I do?

rrauenza
  • 215
  • 2
  • 7
Human
  • 511
  • 2
  • 9
  • 22

2 Answers2

8

You're missing the - filename argument that instructs Vim to fill the buffer from stdin; cp. :help --

echo $PATH | vim -

Alternatively, you can use your shell's process substitution to create a temporary file descriptor and have Vim edit that "virtual" file.

vim <(echo $PATH)
Ingo Karkat
  • 22,638
  • 2
  • 45
  • 58
  • 1
    If you're using Vim as a pager in place of less/more, try `| vim -R -` to disable the "Save changes?" prompt when you quit. – John Kugelman Oct 24 '18 at 16:45
6

How can I redirect output from stout into vim?

Your question has been answered on AskUbuntu.

The simplest solution is to add - to your command:

echo $PATH | vim -

You can use process substitution (this also works with applications that can't read from STDIN):

vim <(ls -la)

Or use vim's function to read from STDIN:

ls -la | vim -

Source How do I redirect command output to vim in bash?, answer by Chaos

DavidPostill
  • 153,128
  • 77
  • 353
  • 394