Prevent copying of pasted-over text to register.

34 views
Skip to first unread message

DwigtArmyOfChampions

unread,
Aug 10, 2023, 6:37:37 AM8/10/23
to vim_use
Using Vim 8.1. I have some text in my register and I want to overwrite some existing text with the contents of the register. So I go into visual mode and highlight the text I want to replace, then I type P and the contents of the register get replaced. OK, but why is the replaced text now in my register? I want to continue pasting the same text at other spots in my document.

Alessandro Antonello

unread,
Aug 10, 2023, 7:23:01 AM8/10/23
to vim...@googlegroups.com
Hy, my friend.

The Vim unnamed register is used to store any text yanked or deleted using the normal mode mappings like "d", "c", "s" or "x". If you need to keep the text you yanked to use it several times, you need to place it in a "named" register. For example, selecting a word, or sequence of words, and type, in normal mode:

"ya

This will place the selection in the register 'a'. When you need to paste the text in this register you will use, also in normal mode:

"ap

See the help at 'registers'

:h registers

Also see "Copying and moving text":

:h copy-move

Regards,


Em qui., 10 de ago. de 2023 às 07:37, DwigtArmyOfChampions <dwightarmy...@hotmail.com> escreveu:
Using Vim 8.1. I have some text in my register and I want to overwrite some existing text with the contents of the register. So I go into visual mode and highlight the text I want to replace, then I type P and the contents of the register get replaced. OK, but why is the replaced text now in my register? I want to continue pasting the same text at other spots in my document.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/130ad198-6d00-4928-91c7-c4c7e34a3f40n%40googlegroups.com.

Tim Chase

unread,
Aug 10, 2023, 9:24:11 AM8/10/23
to vim...@googlegroups.com
The typical way is to yank the text you want which puts it in the
"0 register, and you can then paste that over visual selections
explicitly with

"0p

which doesn't overwrite the "0 register, so you can do that multiple
times.

-tim





Christian Brabandt

unread,
Aug 10, 2023, 11:32:05 AM8/10/23
to vim...@googlegroups.com

On Do, 10 Aug 2023, Tim Chase wrote:

> The typical way is to yank the text you want which puts it in the
> "0 register, and you can then paste that over visual selections
> explicitly with
>
> "0p
>
> which doesn't overwrite the "0 register, so you can do that multiple
> times.

With some newer Vims, you can use `P` from visual mode without changing
the unnamed register.

Best,
Christian
--
I have a rock garden. Last week three of them died.
-- Richard Diran

wenxin Wang

unread,
Aug 11, 2023, 2:03:50 AM8/11/23
to vim...@googlegroups.com
My vim is version 8.2, And i tested it. Only use 'P' from visual model
didn't prevet changing the unamed register. Anyway, Maybe my verions
isn't the newest.
regards
Wenxin
> --
> --
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/ZNUC6/aN7FOSMMec%40256bit.org.
>

Reply all
Reply to author
Forward
0 new messages