我在尝试制作“选择光标周围的可视块”功能时获得了一些乐趣。
function! ContiguousVBlock()
let [lnum, vcol] = [line('.'), virtcol('.')]
let [top, bottom] = [lnum, lnum]
while matchstr(getline(top-1), '\%'.vcol.'v.') =~# '\S'
let top -= 1
endwhile
while matchstr(getline(bottom+1), '\%'.vcol.'v.') =~# '\S'
let bottom += 1
endwhile
let lines = getline(top, bottom)
let [left, right] = [vcol, vcol]
while len(filter(map(copy(lines), 'matchstr(v:val,"\\%".(left-1)."v.")'),'v:val=~#"\\S"')) == len(lines)
let left -= 1
endwhile
while len(filter(map(copy(lines), 'matchstr(v:val,"\\%".(right+1)."v.")'),'v:val=~#"\\S"')) == len(lines)
let right += 1
endwhile
call setpos('.', [0, top, strlen(matchstr(lines[0], '^.*\%'.left.'v.')), 0])
execute "normal! \<C-V>"
call setpos('.', [0, bottom, strlen(matchstr(lines[-1], '^.*\%'.right.'v.')), 0])
endfunction
nnoremap <Leader>vb :<C-U>call ContiguousVBlock()<CR>
你可以试试<Leader>vb:它应该选择光标周围任何连续的非空白矩形块。纵轴是首选。
也许我稍后会改进它,但现在你可以试试它是否能解决你的问题,如果你愿意的话。
作为我自己尝试的替代方案,您可以尝试流行的插件 textobj-word-column。它为您提供文本对象 ac ic aC iC 以选择一列单词或单词。