I didn't find anything in help about being able to see the commands in
a macro. When I create a mapping I can see what I have typed into the
mapping so I can figure out what I did wrong if my mapping doesn't
work as expected the first time. Is it possible to do something like
this with a recorded macro?

I took the commands I have in a complex mapping and did them manually
with copy and paste within a record session. The recording worked up
to a point and then failed but I don't know where it failed and
without seeing the commands visually I have to redo the recording from
start to finish and hope I get it all done correctly. That is a pain.

Maybe I am thinking about this backwards. Maybe I should use macros
for the simple things and mappings for the more complex. I need to
figure out how to create scripts and functions and stuff like that.

This is what I found in usr_10.txt and repeat.txt following:

usr_10.txt

*10.1*  Record and playback commands

The "." command repeats the preceding change.  But what if you want to do
something more complex than a single change?  That's where command recording
comes in.  There are three steps:

1. The "q{register}" command starts recording keystrokes into the register
   named {register}.  The register name must be between a and z.
2. Type your commands.
3. To finish recording, press q (without any extra character).

You can now execute the macro by typing the command "@{register}".

Take a look at how to use these commands in practice.  You have a list of
filenames that look like this:

        stdio.h ~
        fcntl.h ~
        unistd.h ~
        stdlib.h ~

And what you want is the following:

        #include "stdio.h" ~
        #include "fcntl.h" ~
        #include "unistd.h" ~
        #include "stdlib.h" ~

You start by moving to the first character of the first line.  Next you
execute the following commands:

        qa                      Start recording a macro in register a.
        ^                       Move to the beginning of the line.
        i#include "<Esc>        Insert the string #include " at the beginning
                                of the line.
        $                       Move to the end of the line.
        a"<Esc>                 Append the character double quotation mark (")
                                to the end of the line.
        j                       Go to the next line.
        q                       Stop recording the macro.

Now that you have done the work once, you can repeat the change by typing the
command "@a" three times.
   The "@a" command can be preceded by a count, which will cause the macro to
be executed that number of times.  In this case you would type: >

        3@a


MOVE AND EXECUTE

You might have the lines you want to change in various places.  Just move the
cursor to each location and use the "@a" command.  If you have done that once,
you can do it again with "@@".  That's a bit easier to type.  If you now
execute register b with "@b", the next "@@" will use register b.
   If you compare the playback method with using ".", there are several
differences.  First of all, "." can only repeat one change.  As seen in the
example above, "@a" can do several changes, and move around as well.
Secondly, "." can only remember the last change.  Executing a register allows
you to make any changes and then still use "@a" to replay the recorded
commands.  Finally, you can use 26 different registers.  Thus you can remember
26 different command sequences to execute.


repeat.txt

3. Complex repeats                                      *complex-repeat*

                                                        *q* *recording*
q{0-9a-zA-Z"}           Record typed characters into register {0-9a-zA-Z"}
                        (uppercase to append).  The 'q' command is disabled
                        while executing a register, and it doesn't work inside
                        a mapping.  {Vi: no recording}

q                       Stops recording.  (Implementation note: The 'q' that
                        stops recording is not stored in the register, unless
                        it was the result of a mapping)  {Vi: no recording}

                                                        *@*
@{0-9a-z".=*}           Execute the contents of register {0-9a-z".=*} [count]
                        times.  Note that register '%' (name of the current
                        file) and '#' (name of the alternate file) cannot be
                        used.  For "@=" you are prompted to enter an
                        expression.  The result of the expression is then
                        executed.  See also |@:|.  {Vi: only named registers}

                                                        *@@* *E748*
@@                      Repeat the previous @{0-9a-z":*} [count] times.

:[addr]*{0-9a-z".=}                                             *:@* *:star*
:[addr]@{0-9a-z".=*}    Execute the contents of register {0-9a-z".=*} as an Ex
                        command.  First set cursor at line [addr] (default is
                        current line).  When the last line in the register does
                        not have a <CR> it will be added automatically when
                        the 'e' flag is present in 'cpoptions'.
                        Note that the ":*" command is only recognized when the
                        '*' flag is present in 'cpoptions'.  This is NOT the
                        default when 'nocompatible' is used.
                        For ":@=" the last used expression is used.  The
                        result of evaluating the expression is executed as an
                        Ex command.
                        Mappings are not recognized in these commands.
                        {Vi: only in some versions} Future: Will execute the
                        register for each line in the address range.

                                                        *:@:*
:[addr]@:               Repeat last command-line.  First set cursor at line
                        [addr] (default is current line).  {not in Vi}

                                                        *:@@*
:[addr]@@               Repeat the previous :@{0-9a-z"}.  First set cursor at
                        line [addr] (default is current line).  {Vi: only in
                        some versions}

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to