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

Insert comand output on current text

Expand Messages
  • Cesar Romani
    I want to write the ouptut of 1,.s/^# /&/n into the current text. Let s say that the output of the above command is: 8 matches on 8 lines On the current text
    Message 1 of 10 , Oct 30, 2013
    • 0 Attachment
      I want to write the ouptut of 1,.s/^# /&/n into the current text.
      Let's say that the output of the above command is:
      8 matches on 8 lines

      On the current text I'd like to insert the string "ch007.html" (without
      quotes) without newlines inserted. Is it possible?

      Many thanks in advance,

      --
      Cesar

      --
      --
      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
      ... Now paste with p ... This request I don t understand at all. Please give a before-and-after example. -- -- You received this message from the vim_use
      Message 2 of 10 , Oct 31, 2013
      • 0 Attachment
        On Wednesday, October 30, 2013 7:26:44 PM UTC-5, andalou wrote:
        > I want to write the ouptut of 1,.s/^# /&/n into the current text.
        >
        > Let's say that the output of the above command is:
        >
        > 8 matches on 8 lines
        >
        >

        You can get this output with the :redir command. Put it in the unnamed register:

        :redir @"
        :your command here
        :redir END

        Now paste with p

        >
        > On the current text I'd like to insert the string "ch007.html" (without
        >
        > quotes) without newlines inserted. Is it possible?
        >

        This request I don't understand at all. Please give a before-and-after example.

        --
        --
        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.
      • Cesar Romani
        ... Let s say, I have before: Véase el siguiente enlace en el libro and after: Véase el siguiente enlace ch007.html en el libro Regards, -- Cesar -- -- You
        Message 3 of 10 , Nov 1, 2013
        • 0 Attachment
          On 31/10/2013 09:25 p.m., Ben Fritz wrote:
          > On Wednesday, October 30, 2013 7:26:44 PM UTC-5, andalou wrote:
          >> I want to write the ouptut of 1,.s/^# /&/n into the current text.
          >> Let's say that the output of the above command is:
          >> 8 matches on 8 lines
          >
          > You can get this output with the :redir command. Put it in the unnamed
          > register:
          >
          > :redir @"
          > :your command here
          > :redir END
          >
          > Now paste with p
          >
          >> On the current text I'd like to insert the string "ch007.html"
          >> (without quotes) without newlines inserted. Is it possible?
          >
          > This request I don't understand at all. Please give a before-and-after
          > example.

          Let's say, I have before:
          Véase el siguiente enlace en el libro

          and after:
          Véase el siguiente enlace ch007.html en el libro


          Regards,

          --
          Cesar

          --
          --
          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
          ... Ok, but you can achieve this by moving the cursor to the end of enlace , typing a to enter insert mode, then typing ch007.html . But I m sure you know
          Message 4 of 10 , Nov 1, 2013
          • 0 Attachment
            On Friday, November 1, 2013 10:29:12 AM UTC-5, andalou wrote:
            >
            > >> On the current text I'd like to insert the string "ch007.html"
            >
            > >> (without quotes) without newlines inserted. Is it possible?
            >
            > >
            >
            > > This request I don't understand at all. Please give a before-and-after
            >
            > > example.
            >
            >
            >
            > Let's say, I have before:
            >
            > V�ase el siguiente enlace en el libro
            >
            >
            >
            > and after:
            >
            > V�ase el siguiente enlace ch007.html en el libro
            >
            >

            Ok, but you can achieve this by moving the cursor to the end of "enlace", typing 'a' to enter insert mode, then typing " ch007.html". But I'm sure you know how to do that. So what are you really asking? What do you want to do, to get to your resulting text?

            --
            --
            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.
          • Cesar Romani
            ... If I go after the end of enlace and do :1,.s/^# /&/n I get, say: 8 matches on 8 lines then I d like to have ch007.html after enlace. If the above
            Message 5 of 10 , Nov 1, 2013
            • 0 Attachment
              On 01/11/2013 01:32 p.m., Ben Fritz wrote:
              > On Friday, November 1, 2013 10:29:12 AM UTC-5, andalou wrote:
              >>
              >>>> On the current text I'd like to insert the string "ch007.html"
              >>>> (without quotes) without newlines inserted. Is it possible?
              >>
              >>> This request I don't understand at all. Please give a
              >>> before-and-after example.
              >>
              >> Let's say, I have before:
              >>
              >> Véase el siguiente enlace en el libro
              >>
              >> and after:
              >>
              >> Véase el siguiente enlace ch007.html en el libro
              >
              > Ok, but you can achieve this by moving the cursor to the end of
              > "enlace", typing 'a' to enter insert mode, then typing " ch007.html".
              > But I'm sure you know how to do that. So what are you really asking?
              > What do you want to do, to get to your resulting text?

              If I go after the end of "enlace" and do :1,.s/^# /&/n
              I get, say:
              8 matches on 8 lines

              then I'd like to have ch007.html after "enlace."

              If the above command outputs:
              35 matches on 35 lines

              then I'd like to have ch034.html after "enlace."

              I suppose, I can do it manually. Thanks anyway.


              --
              Cesar

              --
              --
              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
              ... OK, now THAT is a much better problem description. We can work with that. ... My comment about doing it manually was because your initial problem
              Message 6 of 10 , Nov 2, 2013
              • 0 Attachment
                On Friday, November 1, 2013 2:44:35 PM UTC-5, andalou wrote:
                >
                >
                >
                > If I go after the end of "enlace" and do :1,.s/^# /&/n
                >
                > I get, say:
                >
                > 8 matches on 8 lines
                >
                >
                >
                > then I'd like to have ch007.html after "enlace."
                >
                >
                >
                > If the above command outputs:
                >
                > 35 matches on 35 lines
                >
                >
                >
                > then I'd like to have ch034.html after "enlace."
                >
                >

                OK, now THAT is a much better problem description. We can work with that.

                >
                > I suppose, I can do it manually. Thanks anyway.
                >
                >

                My comment about doing it manually was because your initial problem description gave NO indication as to where "ch007" came from, nor how you wanted to insert it.

                Actually, you STILL give zero indication how you want to insert it. How do you determine where in the line to insert the number?

                To get everything ready for insertion, do:

                :redir => var
                :1,.s/^# /&/n
                :redir END
                :let @"="ch".printf("%03d",(substitute(var, '^\(\d\+\).*', '\1', '')-1)).".html"

                Now you can paste with p and you'll get ch007.html or similar at the cursor.

                If that's not what you want to do for insertion, you need to share where the text should be inserted, what you want to do to insert it, etc.

                --
                --
                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.
              • John Little
                Ben has answered your question directly ( I want to write the output of ... ) using redir, but a more natural (to me) approach for this would be (assuming you
                Message 7 of 10 , Nov 2, 2013
                • 0 Attachment
                  Ben has answered your question directly ("I want to write the output of ...") using redir, but a more natural (to me) approach for this would be (assuming you want the ch007.html text at the current line)

                  :let n = -1
                  :1,.g/^# /let n += 1
                  ''
                  :put =printf('ch%03d.html, n)

                  The :g leaves the cursor at the last match so '' is used to go back to where you started. (C programmers know about printf, but in case you don't %03d means print an integer in a field 3 characters wide with leading zeroes.)

                  Regards, John Little

                  --
                  --
                  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.
                • Cesar Romani
                  ... )-1)). .html ... Many thanks Ben. It is what I wanted. Regards, -- Cesar -- -- You received this message from the vim_use maillist. Do not top-post!
                  Message 8 of 10 , Nov 2, 2013
                  • 0 Attachment
                    On 02/11/2013 01:06 p.m., Ben Fritz wrote:
                    > [...]
                    > My comment about doing it manually was because your initial problem
                    > description gave NO indication as to where "ch007" came from, nor how
                    > you wanted to insert it.
                    >
                    > Actually, you STILL give zero indication how you want to insert it.
                    > How do you determine where in the line to insert the number?
                    >
                    > To get everything ready for insertion, do:
                    >
                    > :redir => var
                    > :1,.s/^# /&/n
                    > :redir END
                    > :let @"="ch".printf("%03d",(substitute(var, '^\(\d\+\).*', '\1',
                    '')-1)).".html"
                    >
                    > Now you can paste with p and you'll get ch007.html or similar at the
                    > cursor.
                    >
                    > If that's not what you want to do for insertion, you need to share
                    > where the text should be inserted, what you want to do to insert it,
                    > etc.

                    Many thanks Ben. It is what I wanted.

                    Regards,

                    --
                    Cesar

                    --
                    --
                    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.
                  • Cesar Romani
                    ... Thanks Ben and John. Best regards, -- Cesar -- -- You received this message from the vim_use maillist. Do not top-post! Type your reply below the text
                    Message 9 of 10 , Nov 2, 2013
                    • 0 Attachment
                      On 02/11/2013 05:20 p.m., John Little wrote:
                      > Ben has answered your question directly ("I want to write the output
                      > of ...") using redir, but a more natural (to me) approach for this
                      > would be (assuming you want the ch007.html text at the current line)
                      >
                      > :let n = -1
                      > :1,.g/^# /let n += 1
                      > ''
                      > :put =printf('ch%03d.html, n)
                      >
                      > The :g leaves the cursor at the last match so '' is used to go back to
                      > where you started. (C programmers know about printf, but in case you
                      > don't %03d means print an integer in a field 3 characters wide with
                      > leading zeroes.)
                      >
                      > Regards, John Little

                      Thanks Ben and John.

                      Best regards,

                      --
                      Cesar

                      --
                      --
                      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.
                    • Andy Wokula
                      ... You didn t mention that 8 is connected with 7. ... -- Andy -- -- You received this message from the vim_use maillist. Do not top-post! Type your reply
                      Message 10 of 10 , Nov 3, 2013
                      • 0 Attachment
                        Am 01.11.2013 20:44, schrieb Cesar Romani:
                        > On 01/11/2013 01:32 p.m., Ben Fritz wrote:
                        >> On Friday, November 1, 2013 10:29:12 AM UTC-5, andalou wrote:
                        >>>>>
                        >>>>> On the current text I'd like to insert the string "ch007.html"
                        >>>>> (without quotes) without newlines inserted. Is it possible?
                        >>>>
                        >>>> This request I don't understand at all. Please give a
                        >>>> before-and-after example.
                        >>>
                        >>> Let's say, I have before:
                        >>>
                        >>> Véase el siguiente enlace en el libro
                        >>>
                        >>> and after:
                        >>>
                        >>> Véase el siguiente enlace ch007.html en el libro
                        >>
                        >> Ok, but you can achieve this by moving the cursor to the end of
                        >> "enlace", typing 'a' to enter insert mode, then typing " ch007.html".
                        >> But I'm sure you know how to do that. So what are you really asking?
                        >> What do you want to do, to get to your resulting text?
                        >
                        > If I go after the end of "enlace" and do :1,.s/^# /&/n
                        > I get, say:
                        > 8 matches on 8 lines
                        >
                        > then I'd like to have ch007.html after "enlace."
                        >
                        > If the above command outputs:
                        > 35 matches on 35 lines
                        >
                        > then I'd like to have ch034.html after "enlace."
                        >
                        > I suppose, I can do it manually. Thanks anyway.

                        You didn't mention that 8 is connected with 7.

                        :substitute sets v:statusmsg
                        :h v:statusmsg

                        :let filename = printf('ch%03d.html', matchstr(v:statusmsg, '\d\+')-1)

                        Append text after EOL:
                        :call setline('.', getline('.'). filename)
                        :exec 'normal! A'. filename
                        :s/$/\=filename

                        --
                        Andy

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