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
For the sake of completeness, I'll note that while setting a register to contain an empty string doesn't remove the register from the output of the :registers command, Vim does not save registers which have been cleared in this way to the .viminfo file.
Therefore, one other quick-and-dirty alternative for removing specific registers from the list is to clear them using either of the commands you suggest, and then restart Vim.
Another option is to never load any registers. As others have said, registers are loaded from .viminfo. The -i flag is used to specify what viminfo file to use. If you specify NONE, no viminfo, and therefore no registers will be loaded.
vim -i NONE
Remove .viminfo file or delete the register line in the .viminfo file.
You can get the details from Here:
The viminfo file is used to store:
- The command line history.
- The search string history.
- The input-line history.
- Contents of non-empty registers.
- Marks for several files.
- File marks, pointing to locations in files.
- Last search/substitute pattern (for 'n' and '&').
- The buffer list.
- Global variables
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
It is possible to set a value for each used register, similar to romainl's approach:
function! ClearRegisters()
redir => l:register_out
silent register
redir end
let l:register_list = split(l:register_out, '\n')
call remove(l:register_list, 0) " remove header (-- Registers --)
call map(l:register_list, "substitute(v:val, '^.\\(.\\).*', '\\1', '')")
call filter(l:register_list, 'v:val !~ "[%#=.:]"') " skip readonly registers
for elem in l:register_list
execute 'let @'.elem.'= ""'
endfor
endfunction
This avoids including additional register on the output of :registers
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