Loading ...
Sorry, an error occurred while loading the content.

Re: vim script: repeat(\ )

Expand Messages
  • ping
    ... and, this just works - the only issue is I don t know how to repeat the here.. and, I really really don t understand how come this works but the
    Message 1 of 11 , Feb 20, 2013
    • 0 Attachment
      On 02/20/2013 03:12 PM, Ben Fritz wrote:
      > On Wednesday, February 20, 2013 1:35:16 PM UTC-6, ping wrote:
      >> On 02/20/2013 02:30 PM, Ben Fritz wrote:
      >>
      >>> On Wednesday, February 20, 2013 1:14:14 PM UTC-6, ping wrote:
      >>>> nn ,gg :call MyGit("new post:")
      >>>> what's the problem?
      >>> nn, or :nnoremap, is a mapping from normal mode. So, all characters on the right-hand side will be executed by Vim as if you typed them from normal mode.
      >>> In other words, Vim will enter the command line when it "types" the ':' character, inserts the rest of the line on the command line, and then...does nothing, because there is nothing else in the mapping for it to do.
      >>> Follow up your mapping with "<CR>" or "<Enter>" to tell Vim to send the enter key for you.
      >>> I.e. you mapping should be:
      >>> nn ,gg :call MyGit("new post:")<CR>
      >> I just tested, no luck still...
      >>
      >>
      >>
      >> //code:
      >>
      >> function! MyGit(commitmsg)
      >>
      >> let commitmsg=a:commitmsg
      >>
      >> let GitCmd=":
      >>
      >> \!git add -A .;
      >>
      >> \!git commit -m " .
      >>
      >> \commitmsg . ";" . "
      >>
      >> \!git push origin master" .
      >>
      >> \repeat("\<left>", 30)
      >>
      >> exec GitCmd
      >>
      >> endf
      >>
      >> command! -nargs=? MyGit :call MyGit(<q-args>)
      >>
      >> nn ,gg :call MyGit("new post:")<CR>
      >>
      >>
      >>
      >> //result:
      >>
      >> Error detected while processing function MyGit:
      >>
      >> line 8:
      >>
      >> E34: No previous command
      >>
      >> Press ENTER or type command to continue
      >>
      >>
      >>
      >> so that repeat thing still confuses me...
      > You said your problem was that Vim would put a bunch of stuff on your command line but not actually hit enter for you.
      >
      > Now you are beyond that issue and ran into another problem.
      >
      > Strings in Vim cannot be split over multiple lines.
      >
      > Instead of this (which will not work):
      >
      > let mystring = ":
      > \ abc
      > \ def"
      >
      > You need to do this:
      >
      > let mystring = ":"
      > \ ."abc"
      > \ ."def"
      >
      > However, looking at what you are trying to do, this STILL will not work. You have at least two other conceptual problems:
      >
      > 1. You cannot string together commands like :!command1 !command2. No Vim command works that way, you need to separate them with |. :! is special though so that even that won't work, because it will just get passed to the shell. You need to do it like :exec "!command1" | exec "!command2".
      > 2. :exec will not leave the cursor somewhere for input. You can't use a function in this way. If you want to use <Left><Left> repeatedly to place the cursor awaiting further input, you will need to have your function RETURN a value instead of executing it, and additionally use an expression map or abbreviation. See :help :map-<expr>
      >
      and, this just works - the only issue is I don't know how to repeat the
      <left> here..
      and, I really really don't understand how come this works but the
      function version doesn't ...
      confusing...

      nn ,gg :!git add -A .;git commit -m "msg: ";git push origin master"<left>

      --
      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php

      ---
      You received this message because you are subscribed to the Google Groups "vim_use" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • Ben Fritz
      ... Wow, I just tested myself and you re right, line continuation within strings DOES seem to work. I thought I found this to not work a long time ago. But, it
      Message 2 of 11 , Feb 20, 2013
      • 0 Attachment
        On Wednesday, February 20, 2013 2:35:24 PM UTC-6, ping wrote:
        > On 02/20/2013 03:12 PM, Ben Fritz wrote:
        > > Strings in Vim cannot be split over multiple lines.
        > > Instead of this (which will not work):
        > >
        > > let mystring = ":
        > > \ abc
        > > \ def"
        > > You need to do this:
        > > let mystring = ":"
        > > \ ."abc"
        > > \ ."def"
        >
        > it looks this is not true [SNIP]
        > so at least the line continuation for the "let var = " looks fine.

        Wow, I just tested myself and you're right, line continuation within strings
        DOES seem to work. I thought I found this to not work a long time ago. But,
        it looks like this worked way back in 6.2.18, so I have no idea where I got
        this idea. Sorry about that!

        > > However, looking at what you are trying to do, this STILL will not work.
        > > You have at least two other conceptual problems:
        > >
        > > 1. You cannot string together commands like :!command1 !command2. No Vim
        > > command works that way, you need to separate them with |. :! is special
        > > though so that even that won't work, because it will just get passed to
        > > the shell. You need to do it like :exec "!command1" | exec "!command2".
        >
        > this I agree, so I fixed it with just one "!" in the head of the whole
        > string and use ";" to connect multiple external shell commands.
        >
        > > 2. :exec will not leave the cursor somewhere for input.
        >
        > I understand,thanks!
        >
        > > You can't use a function in this way. If you want to use <Left><Left>
        > > repeatedly to place the cursor awaiting further input, you will need to
        > > have your function RETURN a value instead of executing it,
        >
        > this is how I changed my current code.
        >
        > > and additionally use an expression map or abbreviation. See :help :map-<expr>
        >
        > this part I don't understand...
        >
        > I couldn't find a close example to my scenario ...
        >

        :help :map-<expr> has a few. Here's another:

        :nnore <expr> h repeat("\<Left>", 5)

        > strangely that if I use "return GitCmd", I got just nothing...
        > since I already "return" the commands that I needed for the Ex command,
        > shouldn't I now get the whole bunch of the command strings waiting in
        > the vim command line?

        Your mapping should look like:

        :nnore <expr> ,gg ':'.MyGit("new post")

        Then your command can look something like:

        :command! MyGit exec MyGit(<q-args>)

        Your function must do nothing, but return the string you want Vim to put on
        the command line, complete with <Left> characters. I'm not sure whether you
        need to escape them like "\<Left>" or not, :help :map-<expr> should help
        with that.

        --
        --
        You received this message from the "vim_use" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php

        ---
        You received this message because you are subscribed to the Google Groups "vim_use" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
        For more options, visit https://groups.google.com/groups/opt_out.
      • ping
        ... that really works!, so looks the key here is 1) use as you mentioned, 2) use : . func() 3) return the command string from the func great to learn!
        Message 3 of 11 , Feb 21, 2013
        • 0 Attachment
          On 2/20/2013 4:36 PM, Ben Fritz wrote:
          > Your mapping should look like:
          >
          > :nnore <expr> ,gg ':'.MyGit("new post")
          that really works!, so looks the key here is
          1) use <expr> as you mentioned,
          2) use ":" . func()
          3) return the command string from the func

          great to learn!
          >
          > Then your command can look something like:
          >
          > :command! MyGit exec MyGit(<q-args>)
          this also works, but
          it seems the exec helps to
          1) evaluate the expression, but also
          2) execute the result right away.
          is there a way to evaluate the express (1) , but not to "execute"
          them(2) , in "command" ?

          none of these works...
          command! -nargs=* MyGit call MyGit(<q-args>)
          command! -nargs=* MyGit eval(":" . MyGit(<q-args>))

          >
          > Your function must do nothing, but return the string you want Vim to put on
          > the command line, complete with <Left> characters. I'm not sure whether you
          > need to escape them like "\<Left>" or not, :help :map-<expr> should help
          > with that.

          --
          --
          You received this message from the "vim_use" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php

          ---
          You received this message because you are subscribed to the Google Groups "vim_use" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
          For more options, visit https://groups.google.com/groups/opt_out.
        • ping
          ... FYI, for the map, I finalize it with this: nn ,gg : . MyGit( new post: ) . repeat( , 24) -- -- You received this message from the
          Message 4 of 11 , Feb 21, 2013
          • 0 Attachment
            On 2/20/2013 4:36 PM, Ben Fritz wrote:
            > Your mapping should look like:
            >
            > :nnore <expr> ,gg ':'.MyGit("new post")
            FYI, for the map, I finalize it with this:
            nn <expr> ,gg ':' . MyGit("new post:") . repeat("\<left>", 24)

            --
            --
            You received this message from the "vim_use" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php

            ---
            You received this message because you are subscribed to the Google Groups "vim_use" group.
            To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
            For more options, visit https://groups.google.com/groups/opt_out.
          • Ben Fritz
            ... For that, I d use an cabbrev similar to your map. Then you would type :MyGit and it would expand to something completely different
            Message 5 of 11 , Feb 21, 2013
            • 0 Attachment
              On Thursday, February 21, 2013 8:34:17 AM UTC-6, ping wrote:
              > On 2/20/2013 4:36 PM, Ben Fritz wrote:
              >
              > > Your mapping should look like:
              >
              > >
              >
              > > :nnore <expr> ,gg ':'.MyGit("new post")
              >
              > that really works!, so looks the key here is
              >
              > 1) use <expr> as you mentioned,
              >
              > 2) use ":" . func()
              >
              > 3) return the command string from the func
              >
              >
              >
              > great to learn!
              >
              > >
              >
              > > Then your command can look something like:
              >
              > >
              >
              > > :command! MyGit exec MyGit(<q-args>)
              >
              > this also works, but
              >
              > it seems the exec helps to
              >
              > 1) evaluate the expression, but also
              >
              > 2) execute the result right away.
              >
              > is there a way to evaluate the express (1) , but not to "execute"
              >
              > them(2) , in "command" ?
              >
              >
              >
              > none of these works...
              >
              > command! -nargs=* MyGit call MyGit(<q-args>)
              >
              > command! -nargs=* MyGit eval(":" . MyGit(<q-args>))
              >

              For that, I'd use an <expr> cabbrev similar to your <expr> map.

              Then you would type :MyGit<Space> and it would expand to something completely different which you could then edit, or you could type :MyGit<Enter> to execute the default.

              A similar cabbrev technique is used here for vimgrep:

              http://vim.wikia.com/wiki/Find_in_files_within_Vim

              --
              --
              You received this message from the "vim_use" maillist.
              Do not top-post! Type your reply below the text you are replying to.
              For more information, visit http://www.vim.org/maillist.php

              ---
              You received this message because you are subscribed to the Google Groups "vim_use" group.
              To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
              For more options, visit https://groups.google.com/groups/opt_out.
            • ping
              ... thanks! that s also helpful info. I ll try that. -- -- You received this message from the vim_use maillist. Do not top-post! Type your reply below the
              Message 6 of 11 , Feb 21, 2013
              • 0 Attachment
                On 02/21/2013 11:04 AM, Ben Fritz wrote:
                > For that, I'd use an <expr> cabbrev similar to your <expr> map.
                >
                > Then you would type :MyGit<Space> and it would expand to something completely different which you could then edit, or you could type :MyGit<Enter> to execute the default.
                >
                > A similar cabbrev technique is used here for vimgrep:
                >
                > http://vim.wikia.com/wiki/Find_in_files_within_Vim
                thanks! that's also helpful info.
                I'll try that.

                --
                --
                You received this message from the "vim_use" maillist.
                Do not top-post! Type your reply below the text you are replying to.
                For more information, visit http://www.vim.org/maillist.php

                ---
                You received this message because you are subscribed to the Google Groups "vim_use" group.
                To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
                For more options, visit https://groups.google.com/groups/opt_out.
              Your message has been successfully submitted and would be delivered to recipients shortly.