0

I had a large file I was trying to reformat which involved removing the 2nd to nth repeating sets on 2 to 100 lines per duplicate.

The data looked like

element1.element2.element...field.comment

I wanted to remove the repetition in elements after the first instance so of course I went complicated :) and did a macro something like

In a macro Yanked first element on current line to register p and then processed lines yanking the first element into register o and then doing, still in the macro

:if (@p=!@o)|:.s/paste register p//g|else|:norm! j|endif

Now this worked OK except when it got to a line where @p<>@o the :norm! j part stayed in : mode until I manually escaped once or twice then executed the :norm! j command.

I solved the problem an easier way but would like to know why it was only on the else portion that it wouldn't leave :ex mode.

Steve
  • 388
  • 1
  • 3
  • 14

1 Answers1

2

From :help norm

:norm[al][!] {commands}                 *:norm* *:normal*
        ...

        This command cannot be followed by another command,
        since any '|' is considered part of the command.

        ...

        An alternative is to use |:execute|, which uses an
        expression as argument.  This allows the use of
        printable characters to represent special characters.

        Example: >
            :exe "normal \<c-w>\<c-w>"

So this would do the trick:

:if (@p=!@o)|:.s/paste register p//g|else|:exe "norm j"|endif
Mathias Begert
  • 2,354
  • 1
  • 16
  • 26