Inside Vim on Windows, I’m trying to filter the lines in a file through a shell executable. I’m using the following command:
:0,$!sort
The idea being that I’ll sort the lines of the file using the Windows sort command.
The issue is that I get nothing back so, effectively, all the lines in the file are deleted, i.e. they are replaced with nothing (I can recover all the lines using undo u).
Outside of Vim, the following command works fine:
type sort-lines.txt | sort
(“sort-lines.txt” is the test file that I’m working with in vim.)
I’ve tried this with the Windows sort command as well as with the Cygwin sort command. The results are the same.
Interestingly, if I use the following command in Vim:
:0,$!dir
The lines of the file are replaced with the output from the dir command. This makes me think that the external program is executing, but it isn’t correctly receiving the input lines from the file.
Is there something that needs to be adjusted in my configuration to make this work? I checked the value of Vim’s shellpipe option and it is set to:
shellpipe=>%s 2>&1
which doesn’t seem right to me.
Okay, I found the issue.
I had an Autorun CMD script set in my registry. Whenever vim would spin up CMD to run the filter, the Autorun script would run and somehow block the piped-in data from getting in.
To workaround the issue, I changed the value of the vim “shell” variable. Here is what I set it to.
The /d tells CMD not to run any Autorun scripts. The extra backslash after the “cmd.exe” is necessary in order to escape the space character between cmd.exe and the /d.
With this setting in place, filtering works correctly.
For a discussion of Autorun and the /d option see this MSDN article
Thanks, Darcy, for pointing me in the right direction. (BTW, you have a great last name.)