Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

newfound command :norm

0 views
Skip to first unread message

Sven7

unread,
Dec 11, 2009, 5:10:44 AM12/11/09
to
Hello,

This is probably basic stuff for most people on
this list, but some of you may be on the same part
of the learning curve as I. Previously, I thought
it was impossible, in Vim 7,2, to paste normal
mode characters unto the command line for
recording a macro, but have now found a way to do so.

Let's say I have built this macro:

q2fxrzq

(macro 2: find 'x', replace with 'z').

...and then want to make a similar macro to
replace 'b' with 'y' instead. This could be done
by retyping it all in normal mode, but if the
macro is long and complicated it makes sense to
reuse the previous one and change only the
relevant bits.

The way to do that is such:

1) rearrange the macro to 'fbry'
2) copy it
3) in normal mode, type q3:norm [paste in 'fbry']
<enter> q

...and that's it!

/Sven7

Kaz Kylheku

unread,
Dec 11, 2009, 5:52:25 AM12/11/09
to
On 2009-12-11, Sven7 <Sven@7.x> wrote:
> Hello,
>
> This is probably basic stuff for most people on
> this list, but some of you may be on the same part
> of the learning curve as I. Previously, I thought
> it was impossible, in Vim 7,2, to paste normal
> mode characters unto the command line for
> recording a macro, but have now found a way to do so.
>
> Let's say I have built this macro:
>
> q2fxrzq
>
> (macro 2: find 'x', replace with 'z').
>
> ...and then want to make a similar macro to
> replace 'b' with 'y' instead.

Your macro is just text in a yank register.

The following method works even if the macro contains carriage
returns and escaps:

1. Move to a blank line in your edit buffer and
paste the contents register 2 there:

"2p

2. Edit the contents.

2 Put the cursor on the first character of
the edited line and yank to the end of line into register 3:

"3y$

Do not use "3Y because this will add a newline to the register,
which appears as an extra character in the macro playback.

It would be nice if the list of registers (:registers) could just be
edited directly, as a buffer.

Also, you can just assign to a register with let, rather than
interpreting normal mode keystrokes with :norm.

:let @3 = "fbry"

Sven7

unread,
Dec 17, 2009, 6:56:35 PM12/17/09
to
Thanks Kaz, interesting stuff! To restate your
info in newbie-speak:

1) A macro lives is in the same buffer as the name
of the macro -- 1-9, a-Z. The macro recorded using
'qXwwwdwiFOO!<ESC>wwdwiBAR!<ESC>q' is possible to
paste using "Xp and then looks like this:
'wwwdwiFOO! ^[wwwdwiBAR! ^['

2) This line may be edited to, for example,
'wwwdwiBOH! ^[wwwdwiBAH! ^['

3) It is inserted into register Z by putting the

cursor on the first character of the edited line

and yanking to the end of line into register Z:
"Zy$ .

4) This is now a macro named Z that may be run
using @Z !

/Sven

Kenny McCormack

unread,
Dec 18, 2009, 8:59:34 AM12/18/09
to
In article <TyzWm.13705$U5.2...@newsb.telia.net>, Sven7 <Sven@7.x> wrote:
>Thanks Kaz, interesting stuff! To restate your
>info in newbie-speak:
>
>1) A macro lives is in the same buffer as the name
>of the macro -- 1-9, a-Z. The macro recorded using
>'qXwwwdwiFOO!<ESC>wwdwiBAR!<ESC>q' is possible to
>paste using "Xp and then looks like this:
>'wwwdwiFOO! ^[wwwdwiBAR! ^['
>

A couple of nitpicks:
1) Instead of saying 1-9, a-Z, you should think of there being just
26 registers, a-z. The numeric registers (and all the other
ones with non-alphabetic names) should be left to the system.
And the point is that a and A refer to the same register; the
difference in case merely indicates different ways of accessing
the register. You should use a unless/until you understand the
difference.
2) As Kaz indicated, you should not use the word "buffer"; it just
adds confusion. A registers is pretty much exactly the same as
a string variable in "regular" programming languages.

>2) This line may be edited to, for example,
>'wwwdwiBOH! ^[wwwdwiBAH! ^['

It *would* be a good thing if there was some kind of plugin for editing
macros. The current method is a little clunky.

>3) It is inserted into register Z by putting the
>cursor on the first character of the edited line
>and yanking to the end of line into register Z:
>"Zy$ .
>
>4) This is now a macro named Z that may be run
>using @Z !

That should be @z
I'm not sure what @Z does - I suppose I could look and see...

Stan Brown

unread,
Dec 20, 2009, 10:11:09 AM12/20/09
to
Fri, 18 Dec 2009 13:59:34 +0000 (UTC) from Kenny McCormack
<gaz...@shell.xmission.com>:

Actually, @Z or @z will work, and what it does is to run register Z
as a macro.

--
Stan Brown, Oak Road Systems, Tompkins County, New York, USA
http://OakRoadSystems.com
Shikata ga nai...

Sven7

unread,
Dec 31, 2009, 8:12:51 AM12/31/09
to
Nitpicks are welcome. I do remember reading
somewhere that registers 1-9 should be left
alone... Because vim may overwrite them, right?

Actually, what's the issue with a key like <ESC>
being transformed into '^[' when entered in a macro?

/Sven7

Kenny McCormack skrev:

Gary Johnson

unread,
Dec 31, 2009, 8:05:00 PM12/31/09
to
Sven7 <Sven@7.x> wrote:
> Nitpicks are welcome. I do remember reading
> somewhere that registers 1-9 should be left
> alone... Because vim may overwrite them, right?

:help quote_number

> Actually, what's the issue with a key like <ESC>
> being transformed into '^[' when entered in a macro?

^[ is an alternative representation for Escape. ASCII control
characters in the range 0x00 - 0x1f can be generated from most keyboards
by holding the Ctrl key while pressing the key for a printable character
in the range 0x40 - 0x5f. The resulting code is that of the printable
character with the upper bits set to 0.

I can't find a good discussion of this, but there are examples here:

:help digraph-table
:helpgrep \^\[

--
Gary Johnson

Tim Roberts

unread,
Jan 3, 2010, 7:12:32 PM1/3/10
to
Gary Johnson <gary...@eskimo.com> wrote:
>
>^[ is an alternative representation for Escape. ASCII control
>characters in the range 0x00 - 0x1f can be generated from most keyboards
>by holding the Ctrl key while pressing the key for a printable character
>in the range 0x40 - 0x5f. The resulting code is that of the printable
>character with the upper bits set to 0.

Right. [ is 0x5B, Esc is 0x1B, which can also be generated on an ASCII
keyboard by pressing Ctrl-[.
--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

0 new messages