vim在多行之前粘贴多行,没有空白

时间:2013-07-05 07:21:44

标签: vim copy-paste

假设我有这两个块:

1
23
456

hello..
world world
codecode

然后我需要这个块(在 1 hello .. 之间,之间没有任何空格):

1hello..
23world world
456codecode

什么是最好的快捷方式?


我在windows xp和windows 7上使用了gvim7.3.46

这是我的_vimrc

set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin

set diffexpr=MyDiff()
function MyDiff()
  let opt = '-a --binary '
  if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
  if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
  let arg1 = v:fname_in
  if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
  let arg2 = v:fname_new
  if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
  let arg3 = v:fname_out
  if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
  let eq = ''
  if $VIMRUNTIME =~ ' '
    if &sh =~ '\<cmd'
      let cmd = '""' . $VIMRUNTIME . '\diff"'
      let eq = '"'
    else
      let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
    endif
  else
    let cmd = $VIMRUNTIME . '\diff'
  endif
  silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction

我使用C-r",但这不起作用。

1
23
456
hello..
world world
codecode

我使用了C-qyC-p,结果是:

1
23
456

1  hello..
23 world world
456codecode

3 个答案:

答案 0 :(得分:3)

  1. 将光标放在1

  2. 点击<C-v>进入可视屏蔽模式。

  3. 将光标向下移动到456并点击$以选择整个区块。

  4. 点击y以阻止该区块。

  5. 将光标放在h中的hello

  6. 点击P

答案 1 :(得分:3)

我会使用视觉阻止模式。这样做:

  1. 在第一个区块的开头,按<C-v>进入可视区块模式。
  2. 选择相关行,然后按$将选择范围扩展到行尾。
  3. d删除第一个块。这也将复制它。
  4. 然后在第二个块的开头按P,将第一个块粘贴到第二个块之前,中间没有空格。
  5. 第一行范围将为空,因此如果您不想要它们,则必须删除这些行。

答案 2 :(得分:1)

使用递归宏在两个块之间来回跳转,删除和连接线:

qq}jdd''pkgJj@qq

值得注意的击键:

  • ''跳回到您最近跳过的
  • @qq
  • 的定义中调用宏q
  • gJ加入两行,但两行之间没有空格

recursive macro

相关问题