0

I have been trying to make this command into a function which gets called by command, but I am not having much luck with it.

" Clear registers
command! WipeReg for i in range(34,122) | silent! call setreg(nr2char(i), []) | endfor

The aim is to add this:

if has ('nvim')
  :wsh!
else
  :wv!
endif

I use both Neovim and Vim and I can't remember these commands. Whenever use this WipeReg command I always have to refer to my notes to make the register clearing persistent. It would be much more convenient to have it included within the WipeReg command.

1
  • I don't know about Neovim, but you can tell Vim to not persist registers with set viminfo+=<0, so you would only need to do that cleanup once.
    – romainl
    Commented Jun 19, 2023 at 7:43

1 Answer 1

1

I would try that:

function! WipeReg()
  for i in range(34,122)
    silent! call setreg(nr2char(i), [])
  endfor
  if has ('nvim')
    wsh!
  else
    wv!
  endif
endfunction

command! WipeReg call WipeReg()
4
  • 1
    Oh, I was so close. Thanks.
    – paradroid
    Commented Jun 19, 2023 at 7:25
  • Thanks for the feedback :-) Always a pleasure to help. Commented Jun 19, 2023 at 7:27
  • In recent Vims (8.1+, maybe?), you shouldn't often need the bang on command or function
    – D. Ben Knoble
    Commented Jun 20, 2023 at 15:15
  • 1
    8.1.0573 @D.BenKnoble; I still type it out of habit though as 15 years of that is hard to kill 😅 Commented Jun 23, 2023 at 18:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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