cmdline: how to expand `##` in-place?

The name of the pictureThe name of the pictureThe name of the pictureClash 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.










share|improve this question



























    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.










    share|improve this question

























      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.










      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 3 hours ago

























      asked 4 hours ago









      Liu Sha

      339110




      339110




















          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.






          share|improve this answer




















          • 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










          • 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










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "599"
          ;
          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',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          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






























          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.






          share|improve this answer




















          • 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










          • 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














          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.






          share|improve this answer




















          • 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










          • 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












          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.






          share|improve this answer












          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          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 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











          • @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










          • @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











          • @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

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          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













































































          Comments

          Popular posts from this blog

          Long meetings (6-7 hours a day): Being “babysat” by supervisor

          What does second last employer means? [closed]

          One-line joke