How to clear vim registers effectively?
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
AFAIK you can't use built-in commands/functions to make registers disappear from the list. That seems to be doable only by removing them from your ~/.viminfo
which sounds a bit extreme.
this thread on the vim mailing list has a command that clears every register but it doesn't remove them from :reg
:
let regs='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/-"' | let i=0 | while (i<strlen(regs)) | exec 'let @'.regs[i].'=""' | let i=i+1 | endwhile | unlet regs
--- EDIT ---
The command above is no longer needed but here is a breakdown for the curious:
" The value of variable regs is a string made up of all named
" and numbered registers, plus the search, small delete, and
" unnamed registers. A string can be used as a list for our
" use case so we use the most concise method. We could have
" done let regs = ['a', 'b', 'c', etc. instead.
let regs = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/-"'
" We are going to iterate through the string so we initialize
" a loop counter with value 0.
let i = 0
" Here is our loop where we check at each iteration if the loop
" counter is smaller than the length of regs.
while (i < strlen(regs))
" If it is, we programmatically assign an empty string
" to each corresponding register
exec 'let @' . regs[i] . ' = ""'
" and we add 1 to the loop counter.
let i = i + 1
endwhile
" Once we are done, we get rid of the variable we created above
" which is now unnecessary.
unlet regs