Assuming you have Perl and/or Ruby support compiled in, :rubydo
and :perldo
will run a Ruby or Perl one-liner on every line in a range (defaults to entire buffer), with $_
bound to the text of the current line (minus the newline). Manipulating $_
will change the text of that line.
You can use this to do certain things that are easy to do in a scripting language but not so obvious using Vim builtins. For example to reverse the order of the words in a line:
:perldo $_ = join ' ', reverse split
To insert a random string of 8 characters (A-Z) at the end of every line:
:rubydo $_ += ' ' + (1..8).collect{('A'..'Z').to_a[rand 26]}.join
You are limited to acting on one line at a time and you can't add newlines.