Is there any chance to write the content of the current vim buffer to stdout?
I\'d like to use vim to edit content that was passed via stdin - without the need of a
To print buffer to shell standard output, vim needs to start in Ex mode, otherwise it'll open the "normal" way with its own window and clear any output buffers on quit.
Here is the simplest working example:
$ echo foo | vim -es '+%print' '+:q!' /dev/stdin
foo
The special file descriptor to standard input needs to be specified (/dev/stdin) in order to prevent extra annoying messages.
And here are some string parsing examples:
$ echo This is example. | vim -es '+s/example/test/g' '+%print' '+:q!' /dev/stdin
This is test.
$ echo This is example. | vim - -es '+s/example/test/g' '+%print' '+:q!'
Vim: Reading from stdin...
This is test.
Here is a simple example using ex which is equivalent to vi -e:
ex -s +%p -cq /etc/hosts
Related: