cmdline: how to expand `##` in-place?
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
In Ex mode, ##
can be expanded to the files in the args
list when files are expected, see :h cmdline-special
In Ex commands, at places where a file name can be **used**, the following
characters have a special meaning. These can also be used in the expression
function expand().
Like !ls ##
will expand ##
But echo ##
will not.
However, if I am going to define my own command, how to tell vim
that I want files here so please expand my ##
?
Is there a way to expand them in place (like how zsh
expands *
when you press Tab after it)?
An example
command! -nargs=1 Echo :exe "echo '" . <q-args> . "'"
Now I want to run Echo I am here ##
with ##
expanded.
cmdline
add a comment |Â
up vote
1
down vote
favorite
In Ex mode, ##
can be expanded to the files in the args
list when files are expected, see :h cmdline-special
In Ex commands, at places where a file name can be **used**, the following
characters have a special meaning. These can also be used in the expression
function expand().
Like !ls ##
will expand ##
But echo ##
will not.
However, if I am going to define my own command, how to tell vim
that I want files here so please expand my ##
?
Is there a way to expand them in place (like how zsh
expands *
when you press Tab after it)?
An example
command! -nargs=1 Echo :exe "echo '" . <q-args> . "'"
Now I want to run Echo I am here ##
with ##
expanded.
cmdline
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
In Ex mode, ##
can be expanded to the files in the args
list when files are expected, see :h cmdline-special
In Ex commands, at places where a file name can be **used**, the following
characters have a special meaning. These can also be used in the expression
function expand().
Like !ls ##
will expand ##
But echo ##
will not.
However, if I am going to define my own command, how to tell vim
that I want files here so please expand my ##
?
Is there a way to expand them in place (like how zsh
expands *
when you press Tab after it)?
An example
command! -nargs=1 Echo :exe "echo '" . <q-args> . "'"
Now I want to run Echo I am here ##
with ##
expanded.
cmdline
In Ex mode, ##
can be expanded to the files in the args
list when files are expected, see :h cmdline-special
In Ex commands, at places where a file name can be **used**, the following
characters have a special meaning. These can also be used in the expression
function expand().
Like !ls ##
will expand ##
But echo ##
will not.
However, if I am going to define my own command, how to tell vim
that I want files here so please expand my ##
?
Is there a way to expand them in place (like how zsh
expands *
when you press Tab after it)?
An example
command! -nargs=1 Echo :exe "echo '" . <q-args> . "'"
Now I want to run Echo I am here ##
with ##
expanded.
cmdline
cmdline
edited 3 hours ago
asked 4 hours ago
Liu Sha
339110
339110
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
3
down vote
You could use :h expand()
in your command:
command! -nargs=+ Test echo expand("<args>")
This way :Test foo bar
will echo foo bar
and :Test ##
will echo your argument list.
About the in-place expansion as far as I know this is not possible out of the box.
Thanks for your answer. I added an example, I want to achieve that.
â Liu Sha
3 hours ago
@LiuSha So something likecommand! -nargs=* Ls execute ":!ls " . expand("<args>")
?
â statoxâ¦
3 hours ago
Sorry to have confused you,Ls
is not a good example, because it is a shell command, so thatvim
already knows it should expand it. Here my command is a general purpose command, sometimes I want to show ##, sometimes it is some other things, like options-x
.
â Liu Sha
3 hours ago
@LiuSha Ok with your new example I see what you want to do. I'm not sure there is an elegant way to do it: maybe you could make the command call a function which will treat the arguments as a list and then expand them in a for loop, but that's not really efficient. Maybe someone will come up with a better solution :)
â statoxâ¦
2 hours ago
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
You could use :h expand()
in your command:
command! -nargs=+ Test echo expand("<args>")
This way :Test foo bar
will echo foo bar
and :Test ##
will echo your argument list.
About the in-place expansion as far as I know this is not possible out of the box.
Thanks for your answer. I added an example, I want to achieve that.
â Liu Sha
3 hours ago
@LiuSha So something likecommand! -nargs=* Ls execute ":!ls " . expand("<args>")
?
â statoxâ¦
3 hours ago
Sorry to have confused you,Ls
is not a good example, because it is a shell command, so thatvim
already knows it should expand it. Here my command is a general purpose command, sometimes I want to show ##, sometimes it is some other things, like options-x
.
â Liu Sha
3 hours ago
@LiuSha Ok with your new example I see what you want to do. I'm not sure there is an elegant way to do it: maybe you could make the command call a function which will treat the arguments as a list and then expand them in a for loop, but that's not really efficient. Maybe someone will come up with a better solution :)
â statoxâ¦
2 hours ago
add a comment |Â
up vote
3
down vote
You could use :h expand()
in your command:
command! -nargs=+ Test echo expand("<args>")
This way :Test foo bar
will echo foo bar
and :Test ##
will echo your argument list.
About the in-place expansion as far as I know this is not possible out of the box.
Thanks for your answer. I added an example, I want to achieve that.
â Liu Sha
3 hours ago
@LiuSha So something likecommand! -nargs=* Ls execute ":!ls " . expand("<args>")
?
â statoxâ¦
3 hours ago
Sorry to have confused you,Ls
is not a good example, because it is a shell command, so thatvim
already knows it should expand it. Here my command is a general purpose command, sometimes I want to show ##, sometimes it is some other things, like options-x
.
â Liu Sha
3 hours ago
@LiuSha Ok with your new example I see what you want to do. I'm not sure there is an elegant way to do it: maybe you could make the command call a function which will treat the arguments as a list and then expand them in a for loop, but that's not really efficient. Maybe someone will come up with a better solution :)
â statoxâ¦
2 hours ago
add a comment |Â
up vote
3
down vote
up vote
3
down vote
You could use :h expand()
in your command:
command! -nargs=+ Test echo expand("<args>")
This way :Test foo bar
will echo foo bar
and :Test ##
will echo your argument list.
About the in-place expansion as far as I know this is not possible out of the box.
You could use :h expand()
in your command:
command! -nargs=+ Test echo expand("<args>")
This way :Test foo bar
will echo foo bar
and :Test ##
will echo your argument list.
About the in-place expansion as far as I know this is not possible out of the box.
answered 4 hours ago
statoxâ¦
24.2k659125
24.2k659125
Thanks for your answer. I added an example, I want to achieve that.
â Liu Sha
3 hours ago
@LiuSha So something likecommand! -nargs=* Ls execute ":!ls " . expand("<args>")
?
â statoxâ¦
3 hours ago
Sorry to have confused you,Ls
is not a good example, because it is a shell command, so thatvim
already knows it should expand it. Here my command is a general purpose command, sometimes I want to show ##, sometimes it is some other things, like options-x
.
â Liu Sha
3 hours ago
@LiuSha Ok with your new example I see what you want to do. I'm not sure there is an elegant way to do it: maybe you could make the command call a function which will treat the arguments as a list and then expand them in a for loop, but that's not really efficient. Maybe someone will come up with a better solution :)
â statoxâ¦
2 hours ago
add a comment |Â
Thanks for your answer. I added an example, I want to achieve that.
â Liu Sha
3 hours ago
@LiuSha So something likecommand! -nargs=* Ls execute ":!ls " . expand("<args>")
?
â statoxâ¦
3 hours ago
Sorry to have confused you,Ls
is not a good example, because it is a shell command, so thatvim
already knows it should expand it. Here my command is a general purpose command, sometimes I want to show ##, sometimes it is some other things, like options-x
.
â Liu Sha
3 hours ago
@LiuSha Ok with your new example I see what you want to do. I'm not sure there is an elegant way to do it: maybe you could make the command call a function which will treat the arguments as a list and then expand them in a for loop, but that's not really efficient. Maybe someone will come up with a better solution :)
â statoxâ¦
2 hours ago
Thanks for your answer. I added an example, I want to achieve that.
â Liu Sha
3 hours ago
Thanks for your answer. I added an example, I want to achieve that.
â Liu Sha
3 hours ago
@LiuSha So something like
command! -nargs=* Ls execute ":!ls " . expand("<args>")
?â statoxâ¦
3 hours ago
@LiuSha So something like
command! -nargs=* Ls execute ":!ls " . expand("<args>")
?â statoxâ¦
3 hours ago
Sorry to have confused you,
Ls
is not a good example, because it is a shell command, so that vim
already knows it should expand it. Here my command is a general purpose command, sometimes I want to show ##, sometimes it is some other things, like options -x
.â Liu Sha
3 hours ago
Sorry to have confused you,
Ls
is not a good example, because it is a shell command, so that vim
already knows it should expand it. Here my command is a general purpose command, sometimes I want to show ##, sometimes it is some other things, like options -x
.â Liu Sha
3 hours ago
@LiuSha Ok with your new example I see what you want to do. I'm not sure there is an elegant way to do it: maybe you could make the command call a function which will treat the arguments as a list and then expand them in a for loop, but that's not really efficient. Maybe someone will come up with a better solution :)
â statoxâ¦
2 hours ago
@LiuSha Ok with your new example I see what you want to do. I'm not sure there is an elegant way to do it: maybe you could make the command call a function which will treat the arguments as a list and then expand them in a for loop, but that's not really efficient. Maybe someone will come up with a better solution :)
â statoxâ¦
2 hours ago
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fvi.stackexchange.com%2fquestions%2f17430%2fcmdline-how-to-expand-in-place%23new-answer', 'question_page');
);
Post as a guest
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
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
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