如何删除由vim中的do/end分隔的环绕块
例如
(10..20).map do |i| <CURSOR HERE>
(1..10).map do |j|
p j
end
end
Run Code Online (Sandbox Code Playgroud)
我想做一些事情dsb(删除环绕声块)并得到
(1..10).map do |j|
p j
end
Run Code Online (Sandbox Code Playgroud)
也许你可以制作nnormap。
每个 end/do 对都位于相同的缩进上,因此首先您应该找到对缩进 - 在这种情况下,下一行具有相同的缩进(因为您的光标在行中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>
Run Code Online (Sandbox Code Playgroud)