
Vim and Ruby fit together like beer and pizza, music and dancing: each an art form unto itself, but together they transcend, uh, somersaulting goose bumps. If you aren't already getting to that level with Vim and Ruby you might want to look into the following two Vim plugins: rubycomplete and supertab. Rubycomplete gives you autocomplete for variable names, method names, etc., just like you get in your IDE. Supertab hooks that functionality to the tab key (among other awesomeness), so just like at the command line you can tab complete your thoughts. Wheee!
One side note. To use rubycomplete you need to have a version of vim compiled with ruby support, otherwise you get an error message like this: "E486: Pattern not found: ErrMsg( "Error: Required vim compiled with +ruby"). To get your own version of vim with ruby support compiled in use MacPorts. The precise command you want is 'sudo port install vim +ruby'. On linux you can just apt-get the vim-ruby package and it comes with the plugin by default (but you still have to get supertab yourself). Another technical detail: you need to modify your ~/.vimrc to support all this hotness.
"ruby
autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete
autocmd FileType ruby,eruby let g:rubycomplete_buffer_loading = 1
autocmd FileType ruby,eruby let g:rubycomplete_rails = 1
autocmd FileType ruby,eruby let g:rubycomplete_classes_in_global = 1
"improve autocomplete menu color
highlight Pmenu ctermbg=238 gui=bold
That last bit with the highlight command is there to fix the default rubycomplete color scheme. Out of the box it has a horrible, horrible pink background to the menu.
As an extra bonus, if you like textmate's cmd-T action you'll want to look into fuzzyfinder_textmate. Another awesome vim plugin. Also, because color is key, look into some good vim colorschemes. I use the vividchalk vim colorscheme on my mac and desert256 on linux (see screenshot). desert256 is my favorite but I can't get 256 color support working on my mac, so i settle for vividchalk.
10 comments:
Nice post.
I'm having a couple of issues. rubycomplete isn't working for me. I type ea[tab] and it doesn't give me each, each_with_index, etc. I know I have Ruby support compiled into MacVim because I use other plugins that require it.
Also, I use the koehler color scheme and I still get that nasty pink background for the popup menu. Can you help me out with some decent settings for Pmenu?
Thanks!
Christopher. The tab only works if you installed the supertab plugin, but there is a bit of a glitch with supertab that I haven't had time to look into. Supertab doesn't have all the possible completions until you have run ruby-omni-complete at least once. To do that type ctrl-x, ctrl-o. That should bring up all the completions you would expect. Then subsiquently you will be able to use tab instead of ctrl-x, ctrl-o. Check out this link for more information (http://hasno.info/2006/04/10/vim-7-ruby-omni-completion) As for the color settings... have you edited your vimrc file with the lines I recommend? That got rid of the bad colors for me.
Ahh, running ruby-omni-complete first fixed the issue. Thanks.
Yeah, I did use your vimrc settings and it fixed the ugly pink background, but only for some color schemes. I like the koehler scheme and the popup is still pink in that one.
What color scheme is being used in your screenshot? I downloaded vividchalk and it doesn't look like that at all. Also, my popup menu doesn't look like it does in your screenshot it either. Even with the fixed colors, it shows up with a dark blue background and white text for me.
Thanks.
Ok, figured it out. I'm using MacVim so I needed to use the gui vars.
highlight PMenu gui=bold guibg=#CECECE guifg=#444444
That setting got my menus looking like your screenshot.
Also, I reread your post and now see that the color scheme in your screenshot is desert256.
I've just installed this but in the second column it shows the full path to the file the method is found in, rather than the "m" that your screenshot shows.
Any idea how to change that?
To avoid having to key in Ctrl-X, Ctrl-O, remap it.
let g:SuperTabDefaultCompletionType = "<C-X><C-O>"
Nice post.
I have the following issue.Before using ctrl-x ctrl -o, I get completion for variable names, but not the methods.
However, after running ruby-omni-complete once, I get completion for methods,class etc, but not for the variable name.
remapping
as suggested by Dylan Copeland gives completion for methods etc, but not for variable names.
Is there anyway to fix this?
Thanks.
Post a Comment