开发者

Programming Ruby with Vim on Windows

I'm just 开发者_运维问答starting learning Ruby and decided "wth, let's pick up vim and get used to it in the process". That sounded like a great idea until I actually downloaded gvim and started ... staring at it. Ok, I'm not a total noob, I know how really basic things are done in vim, what I'm looking for is how to setup vim and what plugins I need to have a complete easy-to-use workspace. I searched on the internet but didn't find anything that was straightforward enough for someone who's just starting, plus most of the articles are old.

Any suggestions guys ?

PS : Just to be clear, I'm not looking for a RoR solution, I'm using vim strictly for Ruby development, no Rails involved at all.


Code completion in vim is kind of meh. It is mostly useful when you have a gigantic variable name you don't feel like typing, it will basically just show everything from open buffers when you hit ctrl-p

For opening files, try out either FuzzyFileFinder_Textmate (this can be a pain to set up), or Command-T.Both will do recursive fuzzy searches starting from where you are.

What you really need to learn to go from beginner to intermediate is really grokking how the commands work. It is basically an extremely terse programming language.

For example, yaw will copy the word your cursor is currently in. y is the verb (will do a copy), a is the modifier (means copy the whole thing, not just from where the cursor is) and w is the noun (copy a word). Learning commands like yaw aren't going to get you that far unless you fully understand each piece. If you grok it, next time you want to delete a word, you just need to figure out that the delete command is d, and you will realize that daw will be the way to go.

Another thing to realize is how powerful . is. . will repeat any command that is in your command buffer. So, if I type daw, I delete a word. I move my cursor to the next word and hit . again, which will delete that word too.

But what happens if I want to delete a word and replace it with something else? daw kills it, i drops you into insert mode, you type out the replacement and hit esc. Ok, but was that repeatable? a . now will just repeat the word you copied, not delete the current word.

However, if you typed caw (c will delete, then drop you into insert mode), then the word you want to replace, and esc, your inserting is rolled into the same command as the delete. That means you can . and repeat the same change at another line.

This is immensely powerful. Eventually, you learn what you can dot and what you can't, and mold your workflow around it.

To start with that stuff, I would start by :h text-objects, which will give you a rundown of the common "nouns", and a bunch of modifiers. There really isn't anything as good as actually having a vim master on hand to answer your questions though.


Are you asking for tips on using vim in general, or specifically vim with ruby? For the former, don't worry about the articles being dated; vi, which vim is based-on, is 30+ years old.

vim-ruby is probably a good start, a lot of handy features: http://vim-ruby.rubyforge.org/, but truth is none of it really necessary, it just streamlines your process.

If you want more of a full-fledged IDE, RubyMine is nice.


Tim Pope is a Rubyist who has written a bucket of useful Vim plugins. I especially like vim-pathogen - which is a meta-plugin to manage other plugins - and vim-endwise - which automatically appends an end as appropriate when you start a do or if block.


I decided to start using vim to program a ruby project just like you. I guess this is really late, but check out https://github.com/akitaonrails/vimfiles. It's easy to edit and add to the included plugins, especially if you fork the project. The project keeps up with Mr. Pope's plugins too, so the latest can be just a git pull away!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜