Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I delete the values associated with all the registers in vim?

I found this snippet on the web:

function! ClearRegisters()
    let regs='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/-="*+'
    let i=0
    while (i<strlen(regs))
        exec 'let @'.regs[i].'=""'
        let i=i+1

command! ClearRegisters call ClearRegisters()

It almost works, but it puts an empty value into each register, rather than deleting the register. Crucially, that means that when you then use the :registers command, all the registers are still present, which makes the display cumbersome (although it's worth noting that if you quit vim, and reload it, the registers are then fully emptied, even if viminfo is set up to save them).

How can I fully delete all the registers, so that :registers doesn't display them, and without needing a restart?

share|improve this question
As far as I know there is no way to do this – FDinoff Jul 14 '13 at 22:56
Why exactly do you want to hide those registers? – romainl Jul 15 '13 at 4:56
up vote 2 down vote accepted

Unlike marks, which have a :delmarks command and a special "not set" value, registers cannot be deleted. An empty register is the closest to an "unused" state you can get. (However, Vim and the :registers command do have the special behavior you've observed where uninitialized registers that have not been restored from the viminfo file are skipped in the output.)

I think what you're rather after is an extended :Registers custom command (you can even alias that to the lowercase original command with a :cmap or the cmdalias plugin) which omits empty registers from its output, like this:

function! s:Registers( arguments )
    redir => l:registersOutput
        silent! execute 'registers' a:arguments
    redir END
    for l:line in split(l:registersOutput, "\n")
        if l:line !~# '^"\S\s*$'
            echo l:line
command! -nargs=? Registers call <SID>Registers(<q-args>)

Alternatively, you could write a Vim patch to introduce a :delregisters command. It should not be too difficult to write; it basically has to set the y_regs[i].y_array structure to NULL (see ops.c in the Vim source code).

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .