tags:

views:

169

answers:

1

Hi, a have googled the question, but found nothing - maybe I do not know how to define the search keywords properly in this case.

I like to use folding in vim when I'm developing Ruby on Rails applications. And my foldcolumn is set to 4. But its visualizing of the start and the end of the ruby method is not so simple and obvious ("-" - "def", "|" - "end"):

-def foo
      bar = 1
|end

The question is - is there any plugin for vim, that will show markers (arrows or stmh) near every "def" and "end" like it is done in TextMate (1)?

v def foo
      bar = 1
^ end

Also, as I do not have much experience in vim/ruby, maybe there is another, more elegant way to check that all def-end pairs are closed in a particular file? (matchit.vim is not very comfortable for this need) I hope there is more convenient way to catch lost "ends" than to read "Syntax error" in the console :)

+1  A: 

I'm not sure whether it's quite what you need, but have you tried the 'foldcolumn' option? For example, with:

:set foldcolumn=4

You'll get something like this:

-   def foo
|       bar = 1
|   end

-   def foo2
|       bar = 2
|-      if x == 1
||          bar = 3
||      end
|   end

See :help 'foldcolumn' for more information. Note that you can click on the - signs to close the folds if your Vim is mouse-enabled.

Edit

If you don't like the fold method, you could use signs (assuming your Vim is signs enabled). Try something like this:

command! RubySigns call RubySigns()
" Optional:
au BufReadPost *.rb call RubySigns()
function! RubySigns()
    sign define ruby_end text=^
    sign define ruby_def text=v
    sign unplace *
    g/^\s*\(def\|class\|begin\)\>/exe 'sign place '.line('.').' line='.line('.').' name=ruby_def buffer='.bufnr('%')
    g/^\s*end\>/exe 'sign place '.line('.').' line='.line('.').' name=ruby_end buffer='.bufnr('%')
endfunction

It's probably not perfect (I don't know ruby), but it might give you something to get started.

Al
thank you, but I've mentioned foldcolumn in my question
lipry
ah, sorry: should have read it more carefully...
Al
Hopefully the signs method will be more useful.
Al