I'm trying a simple custom command in Vim to populate the quickfix window with external commands. Currently just trying ls
to get used to the tool. However when I run :cexpr system("ls") | copen
I get annoying extra characters:
|| file1
|| file2
By the way, this does no "honour" the PWD, it just lists the home directory. Both errors might be related?
What is putting these extra characters in the quickfix list?
Vim itself puts the pipes there. They're the separators for filename and line number, respectively, as parsed by the errorformat
option. This is documented in :help quickfix-window-function
:
The default format for the lines displayed in the quickfix window and location list window is:
<filename>|<lnum> col <col>|<text>
This can easily be demonstrated by running a command that is matched by the default errorformat
:
:cexpr system("echo foo.py:123:OMG an error")
which will result in the following quickfix entry:
foo.py|123| OMG an error
So whatever you intend to do with your quickfix evaluation, you should set the errorformat
option accordingly as described in :help errorformat
and :help 'errorformat'
. For a simplistic example using ls
, it may be hard to come up with an errorformat
that makes much sense.
I don't know how to get rid of the two pipes. I'd advise to go with them and use them. If you really want a quickfix list without a filename and a line number, you may not want quickfix in the first place. Consider using another kind of (temporary) buffer instead. See :help 'buftype'
and :help special-buffers
for more information.
You may also find :help write-compiler-plugin
helpful. The idea is to define a makeprg
(really, this can be any program that produces an output) together with an errorformat
that can parse this output.
I could not reproduce any issues with the working directory.