In a vi
editing session, your last deletion (d
or
x
) or yank (y
) is saved in a buffer. You can access the contents of that
buffer and put the saved text back in your file with the
put command (p
or
P
). This is a frequent sequence of
commands:
5dd delete 5 lines . . . move somewhere else p put the 5 deleted lines back in a new location, below the current line
Fewer new users are aware that vi stores
the last nine (Section 17.7) deletions in numbered
buffers. You can access any of these numbered buffers to restore any (or all) of
the last nine deletions. (Small deletions, of only parts of lines, are not saved
in numbered buffers, however.) Small deletions can be recovered only by using
the p
or P
command immediately after you've made the deletion.
vi also allows you to yank (copy) text to "named" buffers identified by letters. You can fill up to 26 (a-z) buffers with yanked text and restore that text with a put command at any time in your editing session. This is especially important if you want to transfer data between two files, because all buffers except those that are named are lost when you change files. See Section 17.4.
— TOR