14

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?

11

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.

3

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 :)

3

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
  • 1
    Thanks for the command though it doesn't work with read-only registers like ". , "% , ": , "# – Ashok Mar 21 '17 at 8:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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