如何删除由
vim中的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
解决方法
也许你可以制作nnormap.
每个end / do对都在同一个缩进上,所以首先你应该找到pair indent – 在这种情况下,下一行是同一个缩进(因为你的光标在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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。