Re: Convert dot command into macro

68 views
Skip to first unread message

Ben Schmidt

unread,
Oct 18, 2007, 10:10:29 PM10/18/07
to vim...@googlegroups.com, vim...@googlegroups.com
> Sorry to piggyback on this one.
> Even though I do use macros and registers, sometimes I wish there was
> a way to copy the "last command" into a register after the fact. Is
> there?
> I also wish there was an easy way to edit my macros and registers.
> I've resorted to exiting vim, edit .viminfo, and resume editing the
> files again.
> Unfortunately (afaik) the last command is not saved in the .viminfo so
> I can't go and copy it to a register or just edit a long series of
> keystrokes.

Here is a patch to Vim that adds a , register which is basically access to Vim's
internal 'redo buffer' used when '.' is used. At a quick look, it seems to work.
You can thus save your '.' commands to another register and replay them later:

:let @a=@,
@a

I believe @, will have pretty much the same functionality as . except that it
won't automatically change the count or the register number like . does (nor will
this happen if you save to another register, of course).

I wonder what Bram thinks about including this functionality in standard Vim? I
think it would be useful. What do others think?

Also, I haven't tested much. Testing and consequent feedback from others would be
worthwhile. There may be issues with things not being escaped which should be, etc.

Ben.

Send instant messages to your online friends http://au.messenger.yahoo.com

Ben Schmidt

unread,
Oct 18, 2007, 10:11:00 PM10/18/07
to vim...@googlegroups.com, vim...@googlegroups.com
redo_reg_patch

Ben Schmidt

unread,
Oct 18, 2007, 10:51:21 PM10/18/07
to vim...@googlegroups.com
> Here is a patch to Vim that adds a , register which is basically access to Vim's
> internal 'redo buffer' used when '.' is used. At a quick look, it seems to work.
> You can thus save your '.' commands to another register and replay them later:
>
> :let @a=@,
> @a
>
> I believe @, will have pretty much the same functionality as . except that it
> won't automatically change the count or the register number like . does (nor will
> this happen if you save to another register, of course).
>
> I wonder what Bram thinks about including this functionality in standard Vim? I
> think it would be useful. What do others think?
>
> Also, I haven't tested much. Testing and consequent feedback from others would be
> worthwhile. There may be issues with things not being escaped which should be, etc.

My apologies; that was a poor patch. And I thought I'd tested @, but trying it
again showed it didn't work. I have now made sure it doesn't work. The . command
is for that purpose, and implementing it isn't trivial!

Revised more robust patch attached.

Ben.


redo_reg_patch

Matthew Winn

unread,
Oct 19, 2007, 4:25:11 AM10/19/07
to vim...@vim.org
On Fri, 19 Oct 2007 12:59:15 +1000, Ben Schmidt
<mail_ben...@yahoo.com.au> wrote:

> My apologies; that was a poor patch. And I thought I'd tested @, but trying it
> again showed it didn't work. I have now made sure it doesn't work. The . command
> is for that purpose, and implementing it isn't trivial!

Just a thought: if I understand the patch correctly you're using ";
as a hidden internal register. Given that regname is an int, wouldn't
it make more sense to use a value that doesn't appear on the keyboard?
Then you don't take away the possibility of adding a "; register in
the future.

--
Matthew Winn

Alexei Alexandrov

unread,
Oct 19, 2007, 1:22:00 PM10/19/07
to vim...@vim.org, vim...@googlegroups.com
Ben Schmidt wrote:
> ...

>
> I wonder what Bram thinks about including this functionality in standard Vim? I
> think it would be useful. What do others think?
>

I would love to see this functionality in Vim. I miss it for very long
time. It's very typical when you go through a number of files doing "n."
Sometimes you need to do it across the session and I wanted the .
command be saved many times.

I vote for it!

Alexei Alexandrov

unread,
Oct 19, 2007, 1:22:49 PM10/19/07
to vim...@vim.org
Ben Schmidt wrote:
> ...

>
> I wonder what Bram thinks about including this functionality in standard Vim? I
> think it would be useful. What do others think?
>

I would love to see this functionality in Vim. I miss it for very long

Ben Schmidt

unread,
Oct 20, 2007, 1:22:41 AM10/20/07
to vim...@googlegroups.com
> Just a thought: if I understand the patch correctly you're using ";
> as a hidden internal register. Given that regname is an int, wouldn't
> it make more sense to use a value that doesn't appear on the keyboard?
> Then you don't take away the possibility of adding a "; register in
> the future.

Good plan. I'll define a constant.

I also realised I'll have to do some jiggerypokery to get redos involving visual
mode working. Visual mode needs to be entered with 1v, but only v is recorded in
the redo buffer (for technical reasons).

And I ignored the case of literal entry in insert mode, which I shouldn't have. So
a bit of work to do there still, too.

I should have done this one while a bit less rushed! My coding isn't usually this
poor...honest...

Reply all
Reply to author
Forward
0 new messages