Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

For some reason I can't for the life of me figure out how to pass single quotation marks to external tools when using vim. For example, I might want to call Vim's external grep to search for the text "foo (that is, a single quotation mark then the word foo)

So I might try the command:

:grep \"foo *.txt

But this results in the following error message:

!findstr /n \"foo *.txt >C:\Users\[username]\AppData\Local\Temp\VIeC244.tmp 2>&1
shell returned 1
E40: Can't open errorfile C:\Users\[username]\AppData\Local\Temp\VIeC244.tmp

Note that grep is changed to use 'findstr /n' since I'm on windows (and can be verified by running echo &grepprg). What I find is that I can easily execute the search I want if I do it myself from the command line by typing the following:

findstr /n \"foo *.txt

Which works exactly as I'd expect

share|improve this question
Seeing the error message might be helpful. Also, have you tried escaping the quotation mark twice, i.e. \\\"? I can only assume that vim unescapes the parameter(s) given to :grep and calls findstr /n "foo *.txt - which would of course be an invalid command and cause an error. – Sep 14 '13 at 2:09
Right, sorry, I updated the question with the error message. I tried a whole bunch of variations on it, including escaping twice, but couldn't get it working –  eventualEntropy Sep 14 '13 at 2:33
Did you try :!findstr /n \"foo *.txt? If that fails, your working directory (try :pwd) might not be set to what you would expect, so *.txt won't find anything. (By default, Vim doesn't automatically change the working directory to the directory of the current file). – Sep 14 '13 at 10:14
To automatically change the working directory to the directory of the current file/buffer, add the following line to your vimrc: set autochdir – Sep 14 '13 at 10:20
I posted to vim_dev about this...apparently it's a place where the default ( and even the extended "( value for shellxquote fails. I posted a workaround that seems to function for this command as an answer. –  Ben Sep 14 '13 at 19:45

1 Answer 1

up vote 1 down vote accepted

You can try temporarily (or permanently) setting 'shellxquote' to a single quote character, like :set shellxquote=\"

Note this will break some external commands using special characters like &, |, <, >, etc. (all the stuff in shellxescape by default), so you may need to not leave it at that value. But, it looks like this is one place where the default shellxquote value from Vim 7.3.450 is broken.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.