Ruby and Vim

From Schmid.wiki
Jump to: navigation, search

Contents

Vim/Ruby Configuration Files

Or install with

gem install vim-ruby
ruby /ruby/lib/ruby/gems/1.8/gems/vim-ruby-2006.07.11/bin/vim-ruby-install.rb

Ruby Evaluation

Single-line Evaluation

:rub puts 2**16

Output From Ruby into Vim

Put the approximate value of π into the text

:r!ruby -e 'print Math::PI'

Multi-line Evaluation

:rub<<
for x in 1..10
    puts x**2
end
.

Filtering Range with Ruby

Whole file:

:rubyd gsub /something(.*)else/,'\1'

Single line:

:.rubyd gsub /something(.*)else/,'\1'

Reverse whole file:

:rubyd $_.reverse!

This more complex example makes the text uppercase and centers it

:rubyd $_=$_.upcase.center(VIM::evaluate("&tw").to_i)

See the article on Utility Ruby for more filtering examples.

References

Personal tools