vim – 使{和}忽略仅包含空格的行

前端之家收集整理的这篇文章主要介绍了vim – 使{和}忽略仅包含空格的行前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
当您使用{和}中的vim中的段落导航时,它会跳过只包含空格的行,尽管它们否则为空白。

我如何说服vim将“仅空白”线视为段落,所以{和}会跳到他们?

这是一个正确处理计数的修改版本:
function! ParagraphMove(delta,visual,count)
    normal m'
    normal |
    if a:visual
        normal gv
    endif

    if a:count == 0
        let limit = 1
    else
        let limit = a:count
    endif

    let i = 0
    while i < limit
        if a:delta > 0
            " first whitespace-only line following a non-whitespace character           
            let pos1 = search("\\S","W")
            let pos2 = search("^\\s*$","W")
            if pos1 == 0 || pos2 == 0
                let pos = search("\\%$","W")
            endif
        elseif a:delta < 0
            " first whitespace-only line preceding a non-whitespace character           
            let pos1 = search("\\S","bW")
            let pos2 = search("^\\s*$","bW")
            if pos1 == 0 || pos2 == 0
                let pos = search("\\%^","bW")
            endif
        endif
        let i += 1
    endwhile
    normal |
endfunction

nnoremap <silent> } :<C-U>call ParagraphMove( 1,v:count)<CR>
onoremap <silent> } :<C-U>call ParagraphMove( 1,v:count)<CR>
" vnoremap <silent> } :<C-U>call ParagraphMove( 1,1)<CR>
nnoremap <silent> { :<C-U>call ParagraphMove(-1,v:count)<CR>
onoremap <silent> { :<C-U>call ParagraphMove(-1,v:count)<CR>
" vnoremap <silent> { :<C-U>call ParagraphMove(-1,1)<CR>
原文链接:https://www.f2er.com/bash/387377.html

猜你在找的Bash相关文章