If I type:
:echo system('grep -IRn foobar ~/.vim | grep -v backup') Vim displays the output of the shell command:
$ grep -IRn foobar ~/.vim | grep -v backup
Which is the list of files containing the pattern foobar inside the folder ~/.vim, after removing the matches containing the pattern backup.
:echo expand('`grep -IRn foobar ~/.vim | grep -v backup`') Vim does the same thing (without the newline at the end).
:e `=system('grep -IRn foobar ~/.vim | grep -v backup | tail -1 | cut -d: -f1')` Vim edits the last file from the output of the previous shell command.
The last 3 commands work without escaping the pipe. The latter is never interpreted as a command termination, probably because it's protected by the string. Maybe for the same reason this command works:
:echo 'hello | world' But If I want to populate the quickfix list with the same shell command and I type:
:cexpr system('grep -IRn foobar ~/.vim | grep -v backup') I have the following errors:
E115: Missing quote: 'grep -IRn foobar ~/.vim E116: Invalid arguments for function system('grep -IRn foobar ~/.vim E15: Invalid expression: system('grep -IRn foobar ~/.vim It seems that the pipe was interpreted as a command termination, and that it must be escaped:
:cexpr system('grep -IRn foobar ~/.vim \| grep -v backup') The pipe is inside a string, and the command is almost identical to the first one with :echo where the pipe is not escaped.
Why is it suddenly interpreted as a command termination with :cexpr system('shell cmd')?
let a='grep -IRn foobar ~/.vim | grep -v backup'and then:cexpr system(a)it works ?cexpr, the|is used to delimit the vim expression, and not the system one. so vim try to runcexpr system('grep -IRn foobar ~/.vimand thengrep -v backup'), which of course fail.:h :bar, it seems that there are special cases for|, but unfortunately it does not match your problem...execute "cexpr " . system("...")