0

I met a problem when copy some lines in one buffer to any buffer. Here is the details.

For example, I use command '3yy' to copy 3 lines in buffer file1 and want use command 'p' to paste these lines in buffer file2. However, if I do a 'd' command between this two commands to delete some lines in either buffer, the 'p' command will not work anymore. It cannot paste the content I copied using '3yy' before. I am on Vim Window 7.

Zizhao
  • 259
  • 3
  • 13
  • 3
    'd' not only deletes the lines but is similar to 'cut' operation. take a look at [yank-register](http://vimcasts.org/episodes/meet-the-yank-register/) – DOOM Sep 03 '14 at 14:57
  • Thanks everyone, I think I got this! – Zizhao Sep 03 '14 at 15:24
  • This is very similar to this post: [Any way to delete in vim without overwriting your last yank?](http://stackoverflow.com/questions/3638542/any-way-to-delete-in-vim-without-overwriting-your-last-yank) – Peter Rincker Sep 03 '14 at 15:39

2 Answers2

1

The unnamed register contains what you yank and what you cut. You can…

  • use the 0 register which always contains the last yank: "0p
  • delete "for real" with the "black hole register": "_d.

See :help registers.

romainl
  • 186,200
  • 21
  • 280
  • 313
  • A further question. If I want to paste the content in the 5 register for 5 times. How could I do that? – Zizhao Sep 04 '14 at 14:32
  • `5"5p` — that's `count` + `register` + `command`. Note that using number registers like in sashang's answer is a *very* bad idea. – romainl Sep 04 '14 at 14:47
0

Just like DOOM said in the comment, 'd' will yank to the default register overwriting what you yanked previously. If you want to preserve what you yanked, place it in a register. Eg:

"13yy

will place 3 lines into register 1. You can paste them like this:

"1p

sashang
  • 11,704
  • 6
  • 44
  • 58