3

The uppercase register has this nice characteristic of allowing appends to them. However, every time I use them to yank a series of text, when it's time to paste them, I can see the old text from when I last used that same registry.

How can I clear them, prior to doing a series of yanks?

3
  • Hi @Guilherme, I try to close the question :-) Do you still have an aspect of your question that is not answered or could you accept the question using the v button next to the arrow voting buttons. It allow the question to rest :-) Mar 29, 2023 at 21:07
  • 1
    Sorry! I forgot to mark it as done! Mar 31, 2023 at 17:11
  • No problem :-) Thank you for the feedback. Mar 31, 2023 at 22:04

1 Answer 1

6

The uppercase registers and the lowercase ones are actually the same. When you yank using the lowercase version you replace the content of the register. When you yank using the uppercase version you append the content to the register.

Hence the standard answer is: Don't clear the register just use the lowercase version for the first yank.

Otherwise you can use the following call to set the register 'A' to empty string:

:let @a=''

Or, alternatively (from @romainl)

qaq

Which starts recording the macro of register a (qa) and immediately stop recording (q), leaving it empty.

But to clear the 'A' register such that the reg command don't list it (following @filbranden) you can:

:call setreg('a', [])
4
  • 1
    In case it's not obvious to others how to clear a register from normal mode: qaq would clear the a register
    – mattb
    Mar 23, 2023 at 19:50
  • 5
    q<register>q rolls better from the fingers.
    – romainl
    Mar 23, 2023 at 19:51
  • 1
    ...which I first learned years ago from none other than @romainl!
    – mattb
    Mar 23, 2023 at 19:52
  • 1
    You can use :call setreg('a', []) to actually clear the register itself (will no longer show in :reg output), rather than merely emptying it by setting it to an empty string.
    – filbranden
    Mar 23, 2023 at 22:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.