VI and Ruby

I've decided it's way past time to get up to speed with Ruby. After several years of constantly changing my personal idiom for javascript styling due to learning things in pieces, I decided that I would try to learn the Ruby style up front. The two biggies that I've been offending are,
  1. One blank space between comment hash (#) and first character
  2. Spaces (and two of those, btw) not tabs
Since I'm just starting this blog thing, I haven't had the chance yet to mention that I'm a big VI fan. Naturally, I'm doing my Ruby development in VI. So, first I needed to make some use of VI's find and replace expression with backreferencing power for #1,

# Insert a blank space into all comments not beginning with one blank space but be careful to avoid replacing other uses of # (e.g. #{})
:%s/#\(\w\)/# \1/

Nice! That was easy. Yet another experience of feeling pretty good about VI.

Now on to style tip #2. Other than the simple search/replace to clean up my existing code, I had to change my tabs to spaces. Some simple changes to my .vimrc and I was ready to go!

#tab = two spaces
set tabstop=2
#use spaces and not the tab character
set expandtab


Recent posts