how to clear registers?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

how to clear registers?

Konstantin Rozinov
Hi folks,

I'm wondering what is the easiest way to clear all (or as many as possible)
registers in vim?  Also, how do I clear just a single register?

Thanks!
Konstantin

Reply | Threaded
Open this post in threaded view
|

Re: how to clear registers?

A.J.Mechelynck
Konstantin Rozinov wrote:

> Hi folks,
>
> I'm wondering what is the easiest way to clear all (or as many as
> possible) registers in vim?  Also, how do I clear just a single register?
>
> Thanks!
> Konstantin
>
>
>
>

To clear just a single register, I guess ":let @x = ''" (with the single
quotes but not the double quotes) would do. It might still appear in the
":registers" list though (with an empty value). To clear them all, I see
no easy way. Editing the viminfo maybe? but you'd have to know what you
were doing, and avoid overwriting your work unwittingly.

Best regards,
Tony.

Reply | Threaded
Open this post in threaded view
|

Re: how to clear registers?

Tim Chase-2
In reply to this post by Konstantin Rozinov
> I'm wondering what is the easiest way to clear all (or as many as
> possible) registers in vim?  Also, how do I clear just a single register?

Clearing a single register (e.g. register "a") is as simple as

        :let @a=''

It will still appear in the output of ":reg", but it will have an
empty/"clear" value.

To step up from a single value to clearing them all, I suppose
you could do something like

let i=0| while (i<26) | exec 'let
@'.nr2char(i+(char2nr("a"))).'=""' | let i=i+1 | endwhile

(all one line) which would clear those.  Alternatively, if you
want more than just the regular named ("a"..."z") registers, you
could do something like this one-line monstrosity:

let
regs='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/-"'
| let i=0 | while (i<strlen(regs)) | exec 'let @'.regs[i].'=""' |
let i=i+1 | endwhile | unlet regs

where each of the registers you want to clear is in that huge
string.  Fortunately, that can be wrapped in a function once and
called from there out.  I omitted the "*" register, as that has
effects outside gVim, but if needed, you can toss that in the
humongo string too :)

Just a few thoughts.  For more, check out

        :help nr2char
        :he char2nr
        :he expr-[]
        :he :exec
        :he :let
        :he :unlet
        :he :while

Hope this gives you some options.

-tim




Reply | Threaded
Open this post in threaded view
|

Re: how to clear registers?

Tim Chase-2
> Clearing a single register (e.g. register "a") is as simple as
>
>     :let @a=''
>
> It will still appear in the output of ":reg", but it will have an
> empty/"clear" value.

I hate to reply to my own posts, but I was wondering if the
following *should* work (though it doesn't in my vim here)

        :unlet @a

It seems like a reasonable thing to do.  I don't know Vim's
internals, but it seems pretty good most of the time, allowing
you to use variables/@registers/&settings pretty interchangeably.
  Just happens not to work in this situation.  It would make
sense to disallow "unlet"ting of &settings, but given that ":reg"
on a fresh copy of vim doesn't return the lettered registers, it
would make sense that they could be "unlet" to get this same
behavior.

Just a curiosity.

-tim




Reply | Threaded
Open this post in threaded view
|

Re: how to clear registers?

David Rayner
In reply to this post by Konstantin Rozinov


> Hi folks,
>
> I'm wondering what is the easiest way to clear all (or as many as possible)
> registers in vim?  Also, how do I clear just a single register?
>
In normal mode to clear say reg q

type qqq


--
Best Regards
David Rayner MSc CEng
"Ergo bibamus!"

http://www.rayninfo.co.uk/blogger.html


Reply | Threaded
Open this post in threaded view
|

Re: how to clear registers?

Hari Krishna Dara
In reply to this post by Konstantin Rozinov

On Thu, 10 Nov 2005 at 12:44pm, David Rayner wrote:

>
>
> > Hi folks,
> >
> > I'm wondering what is the easiest way to clear all (or as many as possible)
> > registers in vim?  Also, how do I clear just a single register?
> >
> In normal mode to clear say reg q
>
> type qqq
>

This still doesn't take the register out of :reg list (because it is
still treated as having a value, though an empty value).

--
Hari


               
__________________________________
Start your day with Yahoo! - Make it your home page!
http://www.yahoo.com/r/hs