I recently (read: two days ago) decided to switch to vim.
I was using another editor called E-TextEditor, because it was the best editor I could find for Ruby. It has auto-indent, but the coolest thing was the snippets it has, such as creating the skeleton for a method just by typing def and pressing tab. There were other neat features as well, of course.
However, one thing that really annoyed me is that it doesn’t have a way to reindent code. Autoindent is great, and for the most part I didn’t have to think about the indentation, but when I refactor, which is quite often (as it should be), I copy and paste blocks of code into other classes, methods, etc. These new locations often have a different indent level than the former location, so I wanted a way to fix the indentation. This editor has no such feature, so I had to select the entire block of pasted code, and hit tab or shift-tab the appropriate number of times.
That was especially hard when the block spanned many lines, say 20 or more. What you have to realize is that it takes longer for me to select large blocks of text (unless it is select all, of course), because I have to use the arrows, instead of the mouse. Combine that with the fact that my down arrow has been acting up, so it doesn’t always work, and you can see it was getting quite annoying.
I thought of using emacs. It is the only editor that I ever got comfortable with on Linux. Anytime I got a VPS or server, my first action was to install emacs.
I had read that emacs had a ruby mode, so I thought about trying to use this. However, using emacs on Cygwin, I ran into many problems.
The mode just wouldn’t work. I don’t know why, and don’t know much about lisp so couldn’t debug it. Further, many keybindings that are supposed to work with emacs, weren’t working. I couldn’t set a mark with C-@ or C-SPC, for instance. The key combination for indenting a region, which I don’t remember at the moment (I think C-M-\?), wouldn’t work. Of course I could use the long form, but that was just annoying.
Exasperated, I thought of what else I could use. No Windows editor seemed to include everything I wanted, so I was still looking for something I could use on Cygwin.
The only other decent editor I know of is vim. I wasn’t sure if I wanted to try it, though, as it always seemed so difficult and unintuitive. Of course, my experience was limited to occasionally accidently being thrown into vim when I forgot to set the EDITOR environment variable, and quickly executing the only command I knew, :q. I soon learned to use :q! instead, because usually when this happened, I started trying to navigate or type without realizing where I was, and that would invariably execute all sorts of unwanted commands on the buffer.
So, needless to say, my relationship with vim had a rocky start. However, everyone I knew of who used vim, swore by it. I thought this rather odd.
So I decided to read up on it, because I knew it supported ruby. There were so many commands! I read about how to use it for several hours, in the middle of the night, which probably limited my capacity for absorbing the information.
But I got the basic navigation commands, and some additional useful things as well. I opened up vim to try some of them out, and was rather impressed at how simple it was.
Then I had to recompile it with ruby support, which took me a while to figure out because it looked so complicated. Fortunately I got that without too much trouble.
Then I found the plugins. I found a plugin for rails, and several related plugins to make it much easier to use vim for a Rails project. That made it significantly better, especially since this Rails plugin has limited support for RSpec.
I’ve really enjoyed it so far. I’m still getting used to all of the commands, because I’ve done limited coding in it so far. I’ve spent the last two days configuring my .vimrc.
However, last night I actually did some coding in it, and found it to be quite nice. Again it will take some getting used to, but there was something really nice about typing cw followed by the new text to insert, to replace a word, for instance. Or, finding the next method just by typing /def . Before, in the other editor, I would just keep arrowing down until I heard def, because the find dialog really didn’t work that great for me with JAWS. I prefer staying in the main window whenever possible, so it’s nice just to initiate finding text just by typing /.
Oh, and the thing that really clinched it was when I wanted to see the arguments to redirect_to, so I pressed C-], and ended up on the method definition, with the rdoc comments right above. After finding what I was looking for, I pressed C-t to get back to where I was.
Then, when I wanted to jump from the spec to the controller it was spec’ing, I typed :AS, and there I was in the controller in a separate window. I changed the spec, typed :w to save, and my autospec script running in a separate window rran to execute the controller specs. Someone once described it as zen, and I agree that that is the only suitable adjective. It’s just so much lighter and more efficient than the large and bulky editors I have used in the past, yet there really is no compromise on features; I would even say there are more features, such as that reindent.
Oh, yes, the reindent. gg to go to the top of the file, and =G to reindent from the cursor to the end of the file. So incredibly simple.
I’ll update with more information as I learn more, and will probably make a post soon about the plugins that I find useful.
If you enjoyed this post, make sure you subscribe to my RSS feed!