Last Updated: September 30, 2021
· ryrych

Using Vim buffer as a standard input and output for shell commands

Vim buffer can be used both as an input and output for other shell commands.

Output example


Input example

Suppose that you liked the Today I learned idea and after some time you would like to get some statistics about your writing using lingua module.

#!/usr/bin/env ruby

require 'lingua'
input =

report =

By the way the file content above has been inserted with :read ~/lingua.rb. Now getting statistics is as easy as this:

:write ! ruby ~/linuga.rb

Number of paragraphs           259 
Number of sentences            136 
Number of words                1400 
Number of characters           9885 

Average words per sentence     10.29 
Average syllables per word     1.48 

Flesch score                   70.94 
Flesh-Kincaid grade level      5.92 
Fog Index                      7.75 

Please note that the whole buffer content has been redirected to standard input that lingua.rb accepts.