문제

I have found the following in my quest to perform a substitution on even numbered lines only:

:g/^/if !(line('.')%2)|s/foo/bar/g|endif 

Works great. But can someone please explain the need for the | characters in the command section of the :g call?

도움이 되었습니까?

해결책

The | character is the command separator; with it, you can concatenate multiple Ex commands in a single line, without adding newlines. See :help :bar.

So, your conditional is equivalent to the following:

if !(line('.')%2)
    s/foo/bar/g
endif

Note that some Ex commands consume the entire remainder of the command-line and therefore cannot be directly concatenated with |. But you can wrap those commands in :execute "{cmd}".

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top