Skip to main content
added 33 characters in body
Source Link
user9433424
  • 6.3k
  • 2
  • 22
  • 30

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')?

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.


: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')?

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')?

added 201 characters in body
Source Link
user9433424
  • 6.3k
  • 2
  • 22
  • 30

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.


: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')?

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


:echo expand('`grep -IRn foobar ~/.vim | grep -v backup`') 

Vim does the same thing.


: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 command termination, probably because it's protected by the string. Maybe for the same reason this command works:

:echo 'hello | world' 

But If 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')?

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.


: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')?

Source Link
user9433424
  • 6.3k
  • 2
  • 22
  • 30

Why is a pipe interpreted as a command termination in :cexpr system('shell cmd')?

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


:echo expand('`grep -IRn foobar ~/.vim | grep -v backup`') 

Vim does the same thing.


: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 command termination, probably because it's protected by the string. Maybe for the same reason this command works:

:echo 'hello | world' 

But If 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')?