9

I'm looking for a fast way to select a block of text in visual-block mode. I deal with files of this nature:

aaaa bbbb cccc
aaaa bbbb cccc
aaaa bbbb cccc

dddd Xeee ffff
dddd eeee ffff
dddd eeee ffff

gggg hhhh iiii
gggg hhhh iiii
gggg hhhh iiii

My goal is to select the middle block in visual-block mode. I would do:

  1. Navigate to the corner (where the X is)
  2. Ctrl-V
  3. 'e' to extend selection to the end of block
  4. 'jj' or '2j' to extend the selection downward to the bottom of the block.

I'm looking for an alternative to (4) that, similar to 'e', would move to the last row of the block. In this simple example 'jj' is not too inconvenient, but sometimes these are large blocks.

There's a similar question here , but that involves jumping a pre-determined number of lines. Is there a way to do this, again an analog to 'e', but moving row-wise instead of column-wise? Thanks!

4

3 回答 3

7

从 开始X,您可以这样做<C-v>}kee

  1. <C-v>- 开始分块视觉模式
  2. }– 转到段落的末尾(据说该动议提供了这个相当复杂的组合的好处)
  3. k- 上面一个排除空行
  4. ee– 将光标从第一列移动到内部块的末尾。
于 2013-09-13T18:57:45.843 回答
4

尝试制作“选择光标周围的可视块”功能时,我获得了一些乐趣。

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以选择一列单词或单词。

于 2013-09-13T19:53:39.743 回答
2

使用 启动可视模式v。然后用 选择内部段落ip。使用 进入可视块模式<C-v>e现在只需根据需要使用 s转到块的末尾。

从块的右下角开始是同样的事情,但不是e使用w.

于 2013-09-13T19:23:58.363 回答