Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Vim, how to cut in block mode but paste in normal mode, inserting as new lines?

Tags:

vim

copy-paste

Every now and then I run into this type of editing problem in Vim.

I have text formatting in a table that I want to turn into a list.

Before:

AAA BBB
AAA BBB
AAA BBB

CCC DDD
CCC DDD
CCC DDD

After:

AAA
AAA
AAA

BBB
BBB
BBB

CCC
CCC
CCC

DDD
DDD
DDD

Of course not as trivial as this example. The blocks can have hairier contents, larger and inconsistent numbers of lines, etc.

The way I do it now seems to be a bit of a hack:

  1. Select a block from the right column in block mode: CTRL-q in the Windows version to select the top-left corner.
    d to cut the block.
  2. Note how many lines were in the block, then manually add that many blank lines.
  3. Go to the top-left of the new blank area I created. SHIFT+p to paste the block into this area.

Step is the rough part.

Doing a normal non-block cut or copy will always paste into "new" lines. A kind of "insert" or "append" operation. Doing a block cut or copy will normally paste in a kind of "overwrite" mode.

Is there a better way to copy or cut in "block mode" but paste in "insert / append mode"?

like image 951
hippietrail Avatar asked Feb 13 '14 10:02

hippietrail


1 Answers

The ex command :put will always paste a register line wise.

Cut the block of text with visual block mode like you have before then execute :put instead of p.

If you want to "cast" pastes in more ways then use @Ingo Karkat's plugin.

For more information see:

:h pu
like image 68
Peter Rincker Avatar answered Sep 28 '22 02:09

Peter Rincker