Copying text in Vim will write the text to buffer. Deleting text also copies. It overwrites the buffer as well. This can be frustrating when you need to do the very common task of copy + replace. The copied text is not preserved in the buffer after the delete command, therefore you cannot paste it. Find a solution to copy and delete in vim without overwriting the buffer below.
Note that the copy command is called yank in Vim, hence the key
y. The delete command is
To copy or delete in vim without overwriting the buffer try one of the following solutions.
- Copy into a “named” register. Here we will name the register “a”, you can use “b” or whatever name you want. Use the following command
To paste from the named register you should use the following:
- Write to the “black hole” register when deleting:
Using one of these solutions should make your vim copy and replace actions much more efficient.