7

On regular AIX vi (not vim, just plain old vi):

I tried to do the following map, but it fails on the "P" or "p" part with the message Cannot use the put command while inside a global command or macro

What I tried (several tries) : ( ^M = Ctrl-v Enter )

#several tries, each have the same result : on use, it aborts on the "p" or "P" part
# q is unmapped on regular vi, so I use it for my test
:map q /something^MY^M?anotherthing^Mp
:map q /something^MY^M?anotherthing^MP
:map q /something^MY?anotherthing^Mp
:map q /something^MY?anotherthing^MP
# then : while in normal mode, I type: q

Each time I use q in normal mode: the first actions work fine (and I can also dd instead of Y), but it then aborts the execution of that mapping on the p or P part.

I tried to Google this error message but see no occurences (but Google search is definitely not what it used to be...)

I'd appreciate any pointer on what workaround I could use to be able to, in a :map, paste something than that same mapping previously yanked/dd'ed.

1 Answer 1

12

I checked the traditional ex-vi. The source is available on github as well, you can find the problem in ex_cmdsub.c. So it has exactly the same issue and throws an

Cannot put inside global/macro

when trying to put while executing a macro. Macro in this case also includes a mapping, so you won't be able to make your mapping work.

I found a bit of documentation on this in the old book "Unix Text processing" which mentions:

All the vi and ex commands can be used in map sequences, with the exception that the p or put command cannot be used to replace entire lines yanked in the same mapping. If you try to yank and then put back a deleted line within a map, you will get the error message:

Cannot put inside global macro.

If you want to move lines from one place to another within a mapping, you can usually get around this restriction using the ex editor’s copy or co command.

So that seems to be expected and the only way around is, is to use the mentioned :co (or :t) ex-command to copy entire lines around.

6
  • 2
    I'm so lucky that I've spent most of my life in vim. One of my favorite things to do with mapped keys is cut and paste stuff. It conveniently worked out that my vi skills were not that advanced before Linux took over.
    – chicks
    Commented Jul 11 at 18:56
  • 2
    @Christian Brabrandt Looking at your photo, your knowledge is quite advanced for your age!
    – kackle123
    Commented Jul 12 at 18:02
  • 1
    ☺I am a smart toddler ;) Commented Jul 12 at 21:21
  • I really appreciate the research you did! But I am not sure how I can do a command mode command (:co) inside a normal mode macro? Commented Jul 13 at 23:21
  • 1
    Well, instead of using Y and p to map, map the :co command. Commented Jul 14 at 8:43

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