How to Jump from Do to End of a Ruby Block Using Vim

How to jump from do to end of a Ruby block using Vim?

The matchit plugin allows matching more than just parentheses and comments. A ruby version can be found here.

Is there any command to go to the end (or beginning) of a Ruby block using vim

Looks like there is an official package at rubyforge that has some support for this:

The Ruby ftplugin now includes Ruby specific implementations for the [[, ]],
[], ][, [m, ]m, [M, and ]M normal mode commands. These allow you to move to
move quickly between module, class and method declarations.

Edit: The README says that these files are included in the default VIM distro but they don't work for me in GVIM on Windows, '{' and '}' seem to work on vim under Linux

Jumping from start to end of code block - vim

With the matchit plugin (that ships with Vim, see :help matchit), you can define def and end as additional keywords to match with %.

If that doesn't suffice, my CountJump plugin allows you to create custom motions and text objects for any pair of patterns.

How to delete ruby surrounding block (do/end) in vim

Maybe you can make nnormap.

Every end/do pair is on the same indent, so firstly you should find pair indent - in this case, next line for the same indent (Cause your cursor is in do line.)

So you can make vimscript function with finding next indent line and delete it.

This is an example of the function. You can customize you want - i.e.) set indent for resting lines.

function! DeleteWithSameIndent(inc)
" Get the cursor current position
let currentPos = getpos('.')
let currentLine = currentPos[1]
let firstLine = currentPos[1]
let matchIndent = 0
d

" Look for a line with the same indent level whithout going out of the buffer
while !matchIndent && currentLine != line('$') + 1 && currentLine != -1
let currentLine += a:inc
let matchIndent = indent(currentLine) == indent('.')
endwhile

" If a line is found go to this line
if (matchIndent)
let currentPos[1] = currentLine
call setpos('.', currentPos)
d
endif
endfunction

nnoremap di :call DeleteWithSameIndent(1)<CR>

How to automatically append end to ruby code blocks in vim?

There is a plugin that does just that: endwise.vim.

Replacing matching { braces } with do/end in Vim (Ruby)

There is a Vim plugin called Vim Blockle that performs this function.

Once you install the plugin you put the cursor on the { } do or end and press <Leader>b to swap the block styles.

vim trick to align blocks/end keywords in Ruby?

Sure. Just select the relevant block of code and press =.



Related Topics



Leave a reply



Submit