system() is the way to go. :h system()
.
You can use the old fashion way (the one that gives you a full control as you would be able to pipe and redirect as many times as it pleases you):
:let res = system("echo ".shellescape(@+)." | the-filter-command")
:put=res
However, you may have issues with line-endings (the last character needs to be chomped). Hence this second solution where vim uses a temporary file and pass it to the filter program:
:let res = system(the-filter-command, @+)
:put=res
There is also another way to accomplish this if you play with another buffer:
:new
:put=@+
:%!the-filter-command
:%d +
:bd
:put=@+
Last note: Vim already has a few filters of its own like :sort
, uniq
is also possible natively (but a little bit more complex), ...