2

I'm trying to fully understand the following command in Vim:

:exe "grep -R " . shellescape(expand("<cWORD>")) . " ."<cr>

I got the use of expand function (force the expansion of into the actual string before it gets passed to shellescape) and shellescape command itself ( from Vim help page: Escape {string} for use as a shell command argument).

What I do not understand, from help itself either, is that use of dots, one before and one after shellescape command.

Again, both of the dots are preceeded and followed by an empty space. And if I use :

:exe "grep -R "shellescape(expand("<cWORD>"))" ."<cr>

which is the same command without those dots, I (apparently) get the same result.

Can anybody give a detailed explanation?

Thank you

3

If you pass multiple strings to the :execute command it will join them together, adding a space between each string. The . operator concatenates strings without adding a space. In this command, adding an extra space won’t break it, so either way works fine. See :help :execute and :help expr-..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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