Escaping Shell Command Arguments in Vim
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
vim
add a comment |
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
vim
.
is the string concatenation operator in Vim. Most other languages use+
. It looks like your example command is missing at least one"
as well.
– Jim Stewart
Nov 25 '18 at 16:43
1
expr6 . expr6 .. String concatenation
– phd
Nov 25 '18 at 18:17
add a comment |
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
vim
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
vim
vim
asked Nov 25 '18 at 16:22
DanieleDaniele
318
318
.
is the string concatenation operator in Vim. Most other languages use+
. It looks like your example command is missing at least one"
as well.
– Jim Stewart
Nov 25 '18 at 16:43
1
expr6 . expr6 .. String concatenation
– phd
Nov 25 '18 at 18:17
add a comment |
.
is the string concatenation operator in Vim. Most other languages use+
. It looks like your example command is missing at least one"
as well.
– Jim Stewart
Nov 25 '18 at 16:43
1
expr6 . expr6 .. String concatenation
– phd
Nov 25 '18 at 18:17
.
is the string concatenation operator in Vim. Most other languages use +
. It looks like your example command is missing at least one "
as well.– Jim Stewart
Nov 25 '18 at 16:43
.
is the string concatenation operator in Vim. Most other languages use +
. It looks like your example command is missing at least one "
as well.– Jim Stewart
Nov 25 '18 at 16:43
1
1
expr6 . expr6 .. String concatenation
– phd
Nov 25 '18 at 18:17
expr6 . expr6 .. String concatenation
– phd
Nov 25 '18 at 18:17
add a comment |
1 Answer
1
active
oldest
votes
:help :execute
already explains that.
As you can see from the :exe[cute] {expr1} ..
syntax, it takes multiple arguments.
Multiple arguments are concatenated, with a space in
between. To avoid the extra space use the "."
operator to concatenate strings into one argument.
:help expr-.
explains that the operator for String concatenation in Vimscript is .
(not +
like in many other languages; in Vimscript, this solely is for adding numbers or Lists). The empty space around it is optional, but often given for better readability.
In summary, if you need to concatenate Strings with spaces, you can either use .
and include the space inside one of the Strings, or pass separate arguments to :execute
and let it add the spaces implicitly, or mix both approaches within the same command (readability should be the first priority here).
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53469467%2fescaping-shell-command-arguments-in-vim%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
:help :execute
already explains that.
As you can see from the :exe[cute] {expr1} ..
syntax, it takes multiple arguments.
Multiple arguments are concatenated, with a space in
between. To avoid the extra space use the "."
operator to concatenate strings into one argument.
:help expr-.
explains that the operator for String concatenation in Vimscript is .
(not +
like in many other languages; in Vimscript, this solely is for adding numbers or Lists). The empty space around it is optional, but often given for better readability.
In summary, if you need to concatenate Strings with spaces, you can either use .
and include the space inside one of the Strings, or pass separate arguments to :execute
and let it add the spaces implicitly, or mix both approaches within the same command (readability should be the first priority here).
add a comment |
:help :execute
already explains that.
As you can see from the :exe[cute] {expr1} ..
syntax, it takes multiple arguments.
Multiple arguments are concatenated, with a space in
between. To avoid the extra space use the "."
operator to concatenate strings into one argument.
:help expr-.
explains that the operator for String concatenation in Vimscript is .
(not +
like in many other languages; in Vimscript, this solely is for adding numbers or Lists). The empty space around it is optional, but often given for better readability.
In summary, if you need to concatenate Strings with spaces, you can either use .
and include the space inside one of the Strings, or pass separate arguments to :execute
and let it add the spaces implicitly, or mix both approaches within the same command (readability should be the first priority here).
add a comment |
:help :execute
already explains that.
As you can see from the :exe[cute] {expr1} ..
syntax, it takes multiple arguments.
Multiple arguments are concatenated, with a space in
between. To avoid the extra space use the "."
operator to concatenate strings into one argument.
:help expr-.
explains that the operator for String concatenation in Vimscript is .
(not +
like in many other languages; in Vimscript, this solely is for adding numbers or Lists). The empty space around it is optional, but often given for better readability.
In summary, if you need to concatenate Strings with spaces, you can either use .
and include the space inside one of the Strings, or pass separate arguments to :execute
and let it add the spaces implicitly, or mix both approaches within the same command (readability should be the first priority here).
:help :execute
already explains that.
As you can see from the :exe[cute] {expr1} ..
syntax, it takes multiple arguments.
Multiple arguments are concatenated, with a space in
between. To avoid the extra space use the "."
operator to concatenate strings into one argument.
:help expr-.
explains that the operator for String concatenation in Vimscript is .
(not +
like in many other languages; in Vimscript, this solely is for adding numbers or Lists). The empty space around it is optional, but often given for better readability.
In summary, if you need to concatenate Strings with spaces, you can either use .
and include the space inside one of the Strings, or pass separate arguments to :execute
and let it add the spaces implicitly, or mix both approaches within the same command (readability should be the first priority here).
answered Nov 26 '18 at 12:37
Ingo KarkatIngo Karkat
133k14148199
133k14148199
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53469467%2fescaping-shell-command-arguments-in-vim%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
.
is the string concatenation operator in Vim. Most other languages use+
. It looks like your example command is missing at least one"
as well.– Jim Stewart
Nov 25 '18 at 16:43
1
expr6 . expr6 .. String concatenation
– phd
Nov 25 '18 at 18:17