How to delete the surround block delimited by do/end in ruby with vim
For example
(10..20).map do |i| <CURSOR HERE>
(1..10).map do |j|
p j
end
end
I want to do something like dsb
(delete surround block) and get
(1..10).map do |j|
p j
end
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With