I\'d like to use Vim in the middle of a pipe. This existing post looks like what I\'d like to do, except I was hoping to do it without Python\'s help -- only with bash. [It it
To print buffer to shell standard output, vim
needs to start in Ex mode, otherwise it'll open "normal" way with its own window and clear any output buffers on quit.
Here is the simplest working example:
$ echo foo | vim +%p -escq /dev/stdin
foo
which is equivalent to:
$ echo foo | vim -es '+%print' '+:q!' /dev/stdin
foo
Special file descriptor to standard input needs to be specified (/dev/stdin
) in order to prevent extra annoying messages.
And here are some examples with parsing strings:
$ echo This is example. | vim '+s/example/test/g' '+%p' -escq! /dev/stdin
This is test.
$ echo This is example. | vim - '+s/example/test/g' '+%p' -escq!
Vim: Reading from stdin...
This is test.
Related: