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
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"
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
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...
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...
Actually, what's the issue with a key like <ESC>
being transformed into '^[' when entered in a macro?
/Sven7
Kenny McCormack skrev:
: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
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.