inheritsfrom
inheritsfrom

Reputation: 81

How to let external script modify present vim buffer

Let say I'm editing somefile.txt in Vim. Is there a way to run an external script saved in a file some_perl_script.pl and let the script modify the presently open buffer in place?

Sorry, I've searched, but the keywords I've used give too broad responses. Thanks!

Upvotes: 0

Views: 102

Answers (2)

romainl
romainl

Reputation: 196789

Assuming some_perl_script.pl takes text from standard input and returns text to standard output, Vim allows you to use it as a "filter":

:%!some_perl_script.pl

See :help filter.

Upvotes: 4

FDinoff
FDinoff

Reputation: 31439

Assuming that some_perl_script.pl takes input on stdin and produces output on stdout.

You can use the formatprg option with gq. When you type gq the selected lines will be formated with the program set with formatprg.

So you can put the following in your vimrc (assuming thats how you run some_perl_script.pl)

set formatprg=some_perl_script.pl

Then in the buffer run gggqG to format the whole buffer.

Take a look at :h formatprg and :h gq

Upvotes: 1

Related Questions