Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear vim registers effectively?

Registers in vim are a great feature to store text snippets and even to run commands on the text stored within them. However, I'm a tidy person and tend to clean things up when I'm done.

I know that if I wanted to clear register a, I can use qaq.

I can also execute the following command:

:let @a = '' 

However, these solutions seem like a mere workaround to the problem. When I execute :registers, the list still displays register a (with an empty value), while registers that have otherwise never been used are not displayed.

Is there a way to clear a register with the side-effect of removing the register from this list?

And if so, is there also a way to clear all registers at once, i.e., to reset that list of registers?

like image 743
Robin Klose Avatar asked Oct 17 '13 14:10

Robin Klose


People also ask

How do I clear my registers?

To clear the a register, for instance, I type q a q 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.

How do I access vim registers?

You can also access the registers in insert/command mode with Ctrl-r + register name, like in Ctrl-r r . It will just paste the text in your current buffer. You can use the :reg command to see all the registers and their content, or filter just the ones that you are interested with :reg a b c .

How many registers does Vim have?

Vim has ten different types of registers: 26 Named registers “a to “z (or “A to“Z) The small delete register “- 10 numbered registers “0 to “9.


1 Answers

Since that venerable answer on the mailing list, linked by @romainl, we have setreg('a', []) that clears the register.

Thus, the code could become:

let regs=split('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/-"', '\zs') for r in regs   call setreg(r, []) endfor 
like image 146
Luc Hermitte Avatar answered Oct 01 '22 04:10

Luc Hermitte