TransWikia.com

How can I clear a register/multiple registers completely?

Vi and Vim Asked on August 31, 2021

I quite often use the :registers command to show the contents of all the registers (I forget what I put where, exactly what the role of "*, "., "%, etc. are).

Especially because I set the " option in the viminfo option, and hence my registers are persisted between my vim sessions (which in general I want, in the short term), over time the :registers list gets longer and longer, and hence more and more cumbersome and filled with really old stuff.

So far, the only way I’ve found to fix this is to manually edit some of the ‘old’ register contents out of ~/.viminfo, which I need to do with vim -u NONE and is hence a bit cumbersome.

Is there a cleaner way to wipe all registers, or wipe a specific register, so it no longer appears in the :registers list?

4 Answers

In short, there is not a cleaner way to wipe registers so completely that they disappear from :reg.

Rather than murk around with ~/.viminfo, I tend to "softclear" registers when I'm really and truly done with them by setting them to be blank. To clear the a register, for instance, I type qaq to set the a register to an empty string. Equivalently, :let @a='' does the same.

Then, looking at the output of :reg is still helpful because it is very easy to discern between empty registers and contained registers. On the other hand, I find that essentially all of my named registers lie on the top row (macros) or the main row (useful paste things), and even then I've only used about 15 named registers.

There was a thread on the vim mailing list a few years back that also concluded that there was no easier way to wipe registers.

Correct answer by davidlowryduda on August 31, 2021

For those using Neovim, you might discover that your changes do not persist upon restart. You'll need to execute the following command after clearing a particular register (e.g. after clearing a with qaq):

:wshada!

See also:

Answered by Mateen Ulhaq on August 31, 2021

Put this in your .vimrc:

command! WipeReg for i in range(34,122) | silent! call setreg(nr2char(i), []) | endfor

and clear every register with :WipeReg

If you would like that to happen every time you start Vim also add:

autocmd VimEnter * WipeReg

Answered by laktak on August 31, 2021

For those wanting to remove the register name (say, a) from the :registers list, there is a way to do it now. Run the command :call setreg('a', []).

I found this out from this question on StackOverflow from user @LucHermitte. His answer details how to clear multiple registers. If you want this task to be super easy, get creative with your .vimrc :)

Answered by Jason Cemra on August 31, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP