如何用vim删除在ruby中由do / end分隔的环绕声块
例如
(10..20).map do |i| <CURSOR HERE>
(1..10).map do |j|
p j
end
end
我想做类似dsb
(删除环绕声块)的操作并获取
(1..10).map do |j|
p j
end
答案 0 :(得分:1)
也许您可以制作nnormap。
每个结束/执行对都在同一缩进上,因此首先您应该找到对缩进-在这种情况下,同一缩进的下一行(因为光标在do
行中。)
因此,您可以通过查找下一个缩进行并删除它来使vimscript函数起作用。
这是该功能的示例。您可以根据需要进行自定义-即为休息行设置缩进量。
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>