Vim is a really useful text editor. Its based on commands interface may frighten you but don't worry, it's easy to start playing and you'll start to see its power soon.

In Ubuntu, install the vim-full package:
sudo aptitude install vim-full

Download it here for Windows or see this for other operation systems.

You also could install gvim which is a graphical interface for vim:
sudo aptitude install gvim

And just start the play:

vim args.rb # (or gvim args.rb if you want the graphical interface)
Pulse the a key (<a> afterwards)
$*.each{|n| puts n}
<Esc>
:wq

ruby args.rb arg1 arg2 arg3
>arg1
>arg2
>arg3

vim upcase.rb
Pulse the a key (<a> afterwards)
puts $*[0].upcase
<Esc>
:wq

ruby upcase.rb "hello"
=>HELLO

echo "hello" | ruby upcase.rb
=>

vim upcase.rb
<a>
<use the arrows for moving the cursor>
arg0_or_stdin = $* == [] ? $stdin.read : $*[0]
puts arg0_or_stdin.upcase
<Esc>
:wq

echo "hello" | ruby upcase.rb
=>HELLO

One Response to “Vim and ruby scripts step by step”

  1. Read a mediawiki list in Ruby « Rails City Says:

    [...] - vim and ruby scripts step by step [...]

Leave a Reply