owohnzimmer
owohnzimmer

Reputation: 33

VIM - First command on multiple command on same line being ignored

I am extracting information from several files and I wrote the following command:

:g!/Value/d | %s/.*=//ge | %s/\;//ge | %y

and it basically does: 'delete lines without "Value" | delete everything up to the = sign | remove ";" | copy all to register'

but the first :g!/Value/d is being ignored, it seems the %y is somehow causing it to be ignored as

:g!/Value/d | %s/.*=//ge | %s/\;//ge

properly cleans the document.

I also tried to get a log from the command execution there was nothing helpful there.

I don't see how the last command could affect the first one.

Upvotes: 2

Views: 51

Answers (2)

Ingo Karkat
Ingo Karkat

Reputation: 172698

The | command separator has different precedence depending on the command, as :help :bar explains. For the :global command, it (and following commands) is considered to be part of the command arguments itself. That means that your substitutions and yank is not executed once (after the :global), but actually on every line that :global picks!

You've already found the correct workaround: By wrapping the command in :execute (which respects the | command separation) and quoting it, the following commands are only evaluated after the first command.

Upvotes: 3

owohnzimmer
owohnzimmer

Reputation: 33

So I found a way to work around this

execute 'g!/\.Value/de' | %s/.*=//ge | %s/\;//ge | %y

This will produce the expected behavior, still it is unclear why the bar would not work for the :g command.

Upvotes: 1

Related Questions