3

I want to end up in insert mode after a macro. Is there a way to do that?

A real life example:

Given "foo", I'm wanting to convert it into "$123" where the number is something I have to think about for a bit before recalling the correct one.

Thus, my macro converts "foo" to "$" with the cursor being on $ and then I use a to write the number. If I could include this last a in my macro, I'd save quite a bit of effort due to the task at hand.

0
5

I want to end up in insert mode after a macro. Is there a way to do that?

Yes! You can stop recording a macro using Ctrl+O, q (Ctrl+O is a sequence to enter a single Normal-mode command from Insert mode, see :help i_CTRL-O.) This will result In a macro that, when replayed, will leave you in Insert mode, after inserting any characters you have inserted as part of recording it.


Can macros be edited?

Yes. Macros are simply stored into regular Vim registers, so any operations you do on Vim registers can be used to edit macros.

For example, if you have a macro @a that finds the next occurrence of "foo" and replaces it with $ and you would like to update that macro to also issue an a command to start appending after the $, you can use:

:let @a .= 'a'

See :help :let-@ for using the :let command to modify registers and :help expr-. for the . string concatenation operator (used as .= here to assign back to the same register.)

1
  • 1
    what I sometimes do, to edit macros: :let @a = "<C-R>a" and then use the cursor and change whatever needs to be changed. Jun 27 at 16:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.